# AzureCosmosDBMongoVCoreSemanticCache

> **Class** in `langchain_azure_ai`

📖 [View in docs](https://reference.langchain.com/python/langchain-azure-ai/vectorstores/cache/AzureCosmosDBMongoVCoreSemanticCache)

Cache that uses Cosmos DB Mongo vCore vector-store backend.

## Signature

```python
AzureCosmosDBMongoVCoreSemanticCache(
    self,
    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,
    max_degree: int = 32,
    l_build: int = 50,
    l_search: int = 40,
    ef_search: int = 40,
    application_name: str = 'langchainpy',
    score_threshold: Optional[float] = None,
    compression: Optional[CosmosDBVectorSearchCompression] = None,
    pq_compressed_dims: Optional[int] = None,
    pq_sample_size: Optional[int] = None,
    oversampling: Optional[float] = None,
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `cosmosdb_connection_string` | `str` | Yes | Cosmos DB Mongo vCore connection string |
| `cosmosdb_client` | `Optional[Any]` | No | Cosmos DB Mongo vCore client (default: `None`) |
| `embedding` | `Embedding` | Yes | Embedding provider for semantic encoding and search. |
| `database_name` | `str` | Yes | Database name for the CosmosDBMongoVCoreSemanticCache |
| `collection_name` | `str` | Yes | Collection name for the CosmosDBMongoVCoreSemanticCache |
| `num_lists` | `int` | No | 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 (default: `100`) |
| `dimensions` | `int` | No | Number of dimensions for vector similarity. The maximum number of supported dimensions is 2000 (default: `1536`) |
| `similarity` | `CosmosDBSimilarityType` | No | Similarity metric to use with the IVF index.  Possible options are:     - CosmosDBSimilarityType.COS (cosine distance),     - CosmosDBSimilarityType.L2 (Euclidean distance), and     - CosmosDBSimilarityType.IP (inner product). (default: `CosmosDBSimilarityType.COS`) |
| `kind` | `CosmosDBVectorSearchType` | No | Type of vector index to create. Possible options are:     - vector-ivf     - vector-hnsw     - vector-diskann (default: `CosmosDBVectorSearchType.VECTOR_IVF`) |
| `m` | `int` | No | 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. (default: `16`) |
| `ef_construction` | `int` | No | 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 (default: `64`) |
| `ef_search` | `int` | No | The size of the dynamic candidate list for search        (40 by default). A higher value provides better        recall at the cost of speed. (default: `40`) |
| `max_degree` | `int` | No | Max number of neighbors. Default value is 32, range from 20 to 2048. Only vector-diskann search supports this for now. (default: `32`) |
| `l_build` | `int` | No | l value for index building. Default value is 50, range from 10 to 500. Only vector-diskann search supports this for now. (default: `50`) |
| `l_search` | `int` | No | l value for index searching. Default value is 40, range from 10 to 10000. Only vector-diskann search supports this. (default: `40`) |
| `score_threshold` | `Optional[float]` | No | Maximum score used to filter the vector search documents. (default: `None`) |
| `application_name` | `str` | No | Application name for the client for tracking and logging (default: `'langchainpy'`) |
| `compression` | `Optional[CosmosDBVectorSearchCompression]` | No | compression type for vector indexes. (default: `None`) |
| `pq_compressed_dims` | `Optional[int]` | No | Number of dimensions after compression for product quantization. Must be less than original dimensions. Automatically calculated if omitted. Range: 1-8000. (default: `None`) |
| `pq_sample_size` | `Optional[int]` | No | Number of samples for PQ centroid training. Higher value means better quality but longer build time. Default: 1000. Range: 1000-100000. (default: `None`) |
| `oversampling` | `Optional[float]` | No | 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). (default: `None`) |

## Extends

- `BaseCache`

## Constructors

```python
__init__(
    self,
    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,
    max_degree: int = 32,
    l_build: int = 50,
    l_search: int = 40,
    ef_search: int = 40,
    application_name: str = 'langchainpy',
    score_threshold: Optional[float] = None,
    compression: Optional[CosmosDBVectorSearchCompression] = None,
    pq_compressed_dims: Optional[int] = None,
    pq_sample_size: Optional[int] = None,
    oversampling: Optional[float] = None,
)
```

| Name | Type |
|------|------|
| `cosmosdb_connection_string` | `str` |
| `database_name` | `str` |
| `collection_name` | `str` |
| `embedding` | `Embeddings` |
| `cosmosdb_client` | `Optional[Any]` |
| `num_lists` | `int` |
| `similarity` | `CosmosDBSimilarityType` |
| `kind` | `CosmosDBVectorSearchType` |
| `dimensions` | `int` |
| `m` | `int` |
| `ef_construction` | `int` |
| `max_degree` | `int` |
| `l_build` | `int` |
| `l_search` | `int` |
| `ef_search` | `int` |
| `application_name` | `str` |
| `score_threshold` | `Optional[float]` |
| `compression` | `Optional[CosmosDBVectorSearchCompression]` |
| `pq_compressed_dims` | `Optional[int]` |
| `pq_sample_size` | `Optional[int]` |
| `oversampling` | `Optional[float]` |


## Properties

- `DEFAULT_DATABASE_NAME`
- `DEFAULT_COLLECTION_NAME`
- `cosmosdb_connection_string`
- `cosmosdb_client`
- `embedding`
- `database_name`
- `collection_name`
- `num_lists`
- `dimensions`
- `similarity`
- `kind`
- `m`
- `ef_construction`
- `max_degree`
- `l_build`
- `l_search`
- `ef_search`
- `score_threshold`
- `application_name`
- `compression`
- `pq_compressed_dims`
- `pq_sample_size`
- `oversampling`

## Methods

- [`lookup()`](https://reference.langchain.com/python/langchain-azure-ai/vectorstores/cache/AzureCosmosDBMongoVCoreSemanticCache/lookup)
- [`update()`](https://reference.langchain.com/python/langchain-azure-ai/vectorstores/cache/AzureCosmosDBMongoVCoreSemanticCache/update)
- [`clear()`](https://reference.langchain.com/python/langchain-azure-ai/vectorstores/cache/AzureCosmosDBMongoVCoreSemanticCache/clear)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-azure/blob/7a6a664d617264df8dcb12fcfb1bacc09f21d504/libs/azure-ai/langchain_azure_ai/vectorstores/cache.py#L137)