langchain_community.cache.AzureCosmosDBSemanticCache¶

class langchain_community.cache.AzureCosmosDBSemanticCache(cosmosdb_connection_string: str, database_name: str, collection_name: str, embedding: Embeddings, *, cosmosdb_client: Optional[Any] = None, num_lists: int = 100, similarity: CosmosDBSimilarityType = CosmosDBSimilarityType.COS, kind: CosmosDBVectorSearchType = CosmosDBVectorSearchType.VECTOR_IVF, dimensions: int = 1536, m: int = 16, ef_construction: int = 64, ef_search: int = 40, score_threshold: Optional[float] = None)[source]¶

Cache that uses Cosmos DB Mongo vCore vector-store backend

Parameters
  • cosmosdb_connection_string (str) – Cosmos DB Mongo vCore connection string

  • cosmosdb_client (Optional[Any]) – Cosmos DB Mongo vCore client

  • embedding (Embedding) – Embedding provider for semantic encoding and search.

  • database_name (str) – Database name for the CosmosDBMongoVCoreSemanticCache

  • collection_name (str) – Collection name for the CosmosDBMongoVCoreSemanticCache

  • num_lists (int) – This integer is the number of clusters that the inverted file (IVF) index uses to group the vector data. We recommend that numLists is set to documentCount/1000 for up to 1 million documents and to sqrt(documentCount) for more than 1 million documents. Using a numLists value of 1 is akin to performing brute-force search, which has limited performance

  • dimensions (int) – Number of dimensions for vector similarity. The maximum number of supported dimensions is 2000

  • similarity (CosmosDBSimilarityType) –

    Similarity metric to use with the IVF index.

    Possible options are:
    • CosmosDBSimilarityType.COS (cosine distance),

    • CosmosDBSimilarityType.L2 (Euclidean distance), and

    • CosmosDBSimilarityType.IP (inner product).

  • kind (CosmosDBVectorSearchType) –

    Type of vector index to create. Possible options are:

  • m (int) – The max number of connections per layer (16 by default, minimum value is 2, maximum value is 100). Higher m is suitable for datasets with high dimensionality and/or high accuracy requirements.

  • ef_construction (int) – the size of the dynamic candidate list for constructing the graph (64 by default, minimum value is 4, maximum value is 1000). Higher ef_construction will result in better index quality and higher accuracy, but it will also increase the time required to build the index. ef_construction has to be at least 2 * m

  • ef_search (int) – The size of the dynamic candidate list for search (40 by default). A higher value provides better recall at the cost of speed.

  • score_threshold (Optional[float]) – Maximum score used to filter the vector search documents.

Attributes

DEFAULT_COLLECTION_NAME

DEFAULT_DATABASE_NAME

Methods

__init__(cosmosdb_connection_string, ...[, ...])

param cosmosdb_connection_string

Cosmos DB Mongo vCore connection string

aclear(**kwargs)

Clear cache that can take additional keyword arguments.

alookup(prompt, llm_string)

Look up based on prompt and llm_string.

aupdate(prompt, llm_string, return_val)

Update cache based on prompt and llm_string.

clear(**kwargs)

Clear semantic cache for a given llm_string.

lookup(prompt, llm_string)

Look up based on prompt and llm_string.

update(prompt, llm_string, return_val)

Update cache based on prompt and llm_string.

__init__(cosmosdb_connection_string: str, database_name: str, collection_name: str, embedding: Embeddings, *, cosmosdb_client: Optional[Any] = None, num_lists: int = 100, similarity: CosmosDBSimilarityType = CosmosDBSimilarityType.COS, kind: CosmosDBVectorSearchType = CosmosDBVectorSearchType.VECTOR_IVF, dimensions: int = 1536, m: int = 16, ef_construction: int = 64, ef_search: int = 40, score_threshold: Optional[float] = None)[source]¶
Parameters
  • cosmosdb_connection_string (str) – Cosmos DB Mongo vCore connection string

  • cosmosdb_client (Optional[Any]) – Cosmos DB Mongo vCore client

  • embedding (Embedding) – Embedding provider for semantic encoding and search.

  • database_name (str) – Database name for the CosmosDBMongoVCoreSemanticCache

  • collection_name (str) – Collection name for the CosmosDBMongoVCoreSemanticCache

  • num_lists (int) – This integer is the number of clusters that the inverted file (IVF) index uses to group the vector data. We recommend that numLists is set to documentCount/1000 for up to 1 million documents and to sqrt(documentCount) for more than 1 million documents. Using a numLists value of 1 is akin to performing brute-force search, which has limited performance

  • dimensions (int) – Number of dimensions for vector similarity. The maximum number of supported dimensions is 2000

  • similarity (CosmosDBSimilarityType) –

    Similarity metric to use with the IVF index.

    Possible options are:
    • CosmosDBSimilarityType.COS (cosine distance),

    • CosmosDBSimilarityType.L2 (Euclidean distance), and

    • CosmosDBSimilarityType.IP (inner product).

  • kind (CosmosDBVectorSearchType) –

    Type of vector index to create. Possible options are:

  • m (int) – The max number of connections per layer (16 by default, minimum value is 2, maximum value is 100). Higher m is suitable for datasets with high dimensionality and/or high accuracy requirements.

  • ef_construction (int) – the size of the dynamic candidate list for constructing the graph (64 by default, minimum value is 4, maximum value is 1000). Higher ef_construction will result in better index quality and higher accuracy, but it will also increase the time required to build the index. ef_construction has to be at least 2 * m

  • ef_search (int) – The size of the dynamic candidate list for search (40 by default). A higher value provides better recall at the cost of speed.

  • score_threshold (Optional[float]) – Maximum score used to filter the vector search documents.

async aclear(**kwargs: Any) None¶

Clear cache that can take additional keyword arguments.

Parameters

kwargs (Any) –

Return type

None

async alookup(prompt: str, llm_string: str) Optional[Sequence[Generation]]¶

Look up based on prompt and llm_string.

Parameters
  • prompt (str) –

  • llm_string (str) –

Return type

Optional[Sequence[Generation]]

async aupdate(prompt: str, llm_string: str, return_val: Sequence[Generation]) None¶

Update cache based on prompt and llm_string.

Parameters
  • prompt (str) –

  • llm_string (str) –

  • return_val (Sequence[Generation]) –

Return type

None

clear(**kwargs: Any) None[source]¶

Clear semantic cache for a given llm_string.

Parameters

kwargs (Any) –

Return type

None

lookup(prompt: str, llm_string: str) Optional[Sequence[Generation]][source]¶

Look up based on prompt and llm_string.

Parameters
  • prompt (str) –

  • llm_string (str) –

Return type

Optional[Sequence[Generation]]

update(prompt: str, llm_string: str, return_val: Sequence[Generation]) None[source]¶

Update cache based on prompt and llm_string.

Parameters
  • prompt (str) –

  • llm_string (str) –

  • return_val (Sequence[Generation]) –

Return type

None