Cache

The cache functionality in DataBridge allows you to create and manage specialized caches for efficient querying of your documents.

POST Create Cache

Create a new cache with specified configuration. The cache can be created using metadata filters, specific document IDs, or both.

Parameters:

  • name: Name of the cache to create

  • model: Name of the model to use (e.g. "llama2")

  • gguf_file: Name of the GGUF file to use for the model

  • filters: Optional metadata filters to determine which documents to include

  • docs: Optional list of specific document IDs to include

Returns: Cache configuration object with success status.

from databridge import DataBridge

# Create client instance
db = DataBridge(uri="your-databridge-uri")

# Create cache using filters
cache = db.create_cache(
    name="tech_docs",
    model="llama2",
    gguf_file="llama-2-7b-chat.Q4_K_M.gguf",
    filters={"category": "tech", "topic": "ml"}
)

# Create cache using specific documents
cache = db.create_cache(
    name="research_docs",
    model="llama2",
    gguf_file="llama-2-7b-chat.Q4_K_M.gguf",
    docs=["doc_123", "doc_456"]
)

# Create cache using both filters and specific documents
cache = db.create_cache(
    name="combined_cache",
    model="llama2",
    gguf_file="llama-2-7b-chat.Q4_K_M.gguf",
    filters={"category": "tech"},
    docs=["doc_789"]
)

Response:

GET Get Cache

Get cache configuration by name.

Parameters:

  • name: Name of the cache to retrieve

Returns: Cache existence status.

Response:

POST Update Cache

Update cache with new documents matching its filter.

Parameters:

  • name: Name of the cache to update

Returns: Success status of the update operation.

Response:

POST Add Documents to Cache

Add specific documents to an existing cache.

Parameters:

  • name: Name of the cache

  • docs: List of document IDs to add

Returns: Success status of the add operation.

Response:

POST Query Cache

Query the cache with a prompt to generate a completion.

Parameters:

  • name: Name of the cache

  • query: Query text

  • max_tokens: Optional maximum number of tokens to generate

  • temperature: Optional temperature parameter for controlling randomness

Returns: Completion response with generated text.

Response:

Best Practices

  1. Cache Naming: Use descriptive names for your caches that reflect their content or purpose

  2. Document Organization: Use consistent metadata when ingesting documents to make filtering easier

  3. Cache Updates: Regularly update your caches if you frequently add new documents

  4. Query Parameters:

    • Use lower temperature (0.0-0.3) for more focused, deterministic responses

    • Use higher temperature (0.7-1.0) for more creative responses

    • Adjust max_tokens based on your needed response length

Error Handling

Always wrap cache operations in try-except blocks in production code:

Last updated