AzureCosmosDBMongoVCoreSemanticCache#
- class langchain_azure_ai.vectorstores.cache.AzureCosmosDBMongoVCoreSemanticCache(
- cosmosdb_connection_string: str,
- database_name: str,
- collection_name: str,
- embedding: Embeddings,
- *,
- cosmosdb_client: Any | None = None,
- num_lists: int = 100,
- similarity: CosmosDBSimilarityType = CosmosDBSimilarityType.COS,
- kind: CosmosDBVectorSearchType = CosmosDBVectorSearchType.VECTOR_IVF,
- dimensions: int = 1536,
- m: int = 16,
- ef_construction: int = 64,
- max_degree: int = 32,
- l_build: int = 50,
- l_search: int = 40,
- ef_search: int = 40,
- application_name: str = 'langchainpy',
- score_threshold: float | None = None,
- compression: CosmosDBVectorSearchCompression | None = None,
- pq_compressed_dims: int | None = None,
- pq_sample_size: int | None = None,
- oversampling: float | None = None,
Cache that uses Cosmos DB Mongo vCore vector-store backend.
AzureCosmosDBMongoVCoreSemanticCache constructor.
- 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:
vector-ivf
vector-hnsw
vector-diskann
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.
max_degree (int) – Max number of neighbors. Default value is 32, range from 20 to 2048. Only vector-diskann search supports this for now.
l_build (int) – l value for index building. Default value is 50, range from 10 to 500. Only vector-diskann search supports this for now.
l_search (int) – l value for index searching. Default value is 40, range from 10 to 10000. Only vector-diskann search supports this.
score_threshold (Optional[float]) – Maximum score used to filter the vector search documents.
application_name (str) – Application name for the client for tracking and logging
compression (Optional[CosmosDBVectorSearchCompression]) – compression type for vector indexes.
pq_compressed_dims (Optional[int]) – Number of dimensions after compression for product quantization. Must be less than original dimensions. Automatically calculated if omitted. Range: 1-8000.
pq_sample_size (Optional[int]) – Number of samples for PQ centroid training. Higher value means better quality but longer build time. Default: 1000. Range: 1000-100000.
oversampling (Optional[float]) – The oversampling factor for compressed index. The oversampling factor (a float with a minimum of 1) specifies how many more candidate vectors to retrieve from the compressed index than k (the number of desired results).
Attributes
DEFAULT_COLLECTION_NAME
DEFAULT_DATABASE_NAME
Methods
__init__
(cosmosdb_connection_string, ...[, ...])AzureCosmosDBMongoVCoreSemanticCache constructor.
aclear
(**kwargs)Async clear cache that can take additional keyword arguments.
alookup
(prompt, llm_string)Async look up based on prompt and llm_string.
aupdate
(prompt, llm_string, return_val)Async 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: Any | None = None,
- num_lists: int = 100,
- similarity: CosmosDBSimilarityType = CosmosDBSimilarityType.COS,
- kind: CosmosDBVectorSearchType = CosmosDBVectorSearchType.VECTOR_IVF,
- dimensions: int = 1536,
- m: int = 16,
- ef_construction: int = 64,
- max_degree: int = 32,
- l_build: int = 50,
- l_search: int = 40,
- ef_search: int = 40,
- application_name: str = 'langchainpy',
- score_threshold: float | None = None,
- compression: CosmosDBVectorSearchCompression | None = None,
- pq_compressed_dims: int | None = None,
- pq_sample_size: int | None = None,
- oversampling: float | None = None,
AzureCosmosDBMongoVCoreSemanticCache constructor.
- Parameters:
cosmosdb_connection_string (str) – Cosmos DB Mongo vCore connection string
cosmosdb_client (Any | None) – 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:
vector-ivf
vector-hnsw
vector-diskann
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.
max_degree (int) – Max number of neighbors. Default value is 32, range from 20 to 2048. Only vector-diskann search supports this for now.
l_build (int) – l value for index building. Default value is 50, range from 10 to 500. Only vector-diskann search supports this for now.
l_search (int) – l value for index searching. Default value is 40, range from 10 to 10000. Only vector-diskann search supports this.
score_threshold (float | None) – Maximum score used to filter the vector search documents.
application_name (str) – Application name for the client for tracking and logging
compression (CosmosDBVectorSearchCompression | None) – compression type for vector indexes.
pq_compressed_dims (int | None) – Number of dimensions after compression for product quantization. Must be less than original dimensions. Automatically calculated if omitted. Range: 1-8000.
pq_sample_size (int | None) – Number of samples for PQ centroid training. Higher value means better quality but longer build time. Default: 1000. Range: 1000-100000.
oversampling (float | None) – The oversampling factor for compressed index. The oversampling factor (a float with a minimum of 1) specifies how many more candidate vectors to retrieve from the compressed index than k (the number of desired results).
- async aclear(
- **kwargs: Any,
Async clear cache that can take additional keyword arguments.
- Parameters:
kwargs (Any)
- Return type:
None
- async alookup(
- prompt: str,
- llm_string: str,
Async look up based on prompt and llm_string.
A cache implementation is expected to generate a key from the 2-tuple of prompt and llm_string (e.g., by concatenating them with a delimiter).
- Parameters:
prompt (str) – a string representation of the prompt. In the case of a Chat model, the prompt is a non-trivial serialization of the prompt into the language model.
llm_string (str) – A string representation of the LLM configuration. This is used to capture the invocation parameters of the LLM (e.g., model name, temperature, stop tokens, max tokens, etc.). These invocation parameters are serialized into a string representation.
- Returns:
On a cache miss, return None. On a cache hit, return the cached value. The cached value is a list of Generations (or subclasses).
- Return type:
Sequence[Generation] | None
- async aupdate(
- prompt: str,
- llm_string: str,
- return_val: Sequence[Generation],
Async update cache based on prompt and llm_string.
The prompt and llm_string are used to generate a key for the cache. The key should match that of the look up method.
- Parameters:
prompt (str) – a string representation of the prompt. In the case of a Chat model, the prompt is a non-trivial serialization of the prompt into the language model.
llm_string (str) – A string representation of the LLM configuration. This is used to capture the invocation parameters of the LLM (e.g., model name, temperature, stop tokens, max tokens, etc.). These invocation parameters are serialized into a string representation.
return_val (Sequence[Generation]) – The value to be cached. The value is a list of Generations (or subclasses).
- Return type:
None
- clear(
- **kwargs: Any,
Clear semantic cache for a given llm_string.
- Parameters:
kwargs (Any)
- Return type:
None
- lookup(
- prompt: str,
- llm_string: str,
Look up based on prompt and llm_string.
- Parameters:
prompt (str)
llm_string (str)
- Return type:
Sequence[Generation] | None
- update(
- prompt: str,
- llm_string: str,
- return_val: Sequence[Generation],
Update cache based on prompt and llm_string.
- Parameters:
prompt (str)
llm_string (str)
return_val (Sequence[Generation])
- Return type:
None