# AzureCosmosDBSemanticCache

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/cache/AzureCosmosDBSemanticCache)

Cache that uses Cosmos DB Mongo vCore vector-store backend

## Signature

```python
AzureCosmosDBSemanticCache(
    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,
    ef_search: int = 40,
    score_threshold: Optional[float] = None,
    application_name: str = 'LangChain-CDBMongoVCore-SemanticCache-Python',
)
```

## 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: available as a preview feature only,                    to enable visit https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/preview-features (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`) |
| `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: `'LangChain-CDBMongoVCore-SemanticCache-Python'`) |

## 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,
    ef_search: int = 40,
    score_threshold: Optional[float] = None,
    application_name: str = 'LangChain-CDBMongoVCore-SemanticCache-Python',
)
```

| 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` |
| `ef_search` | `int` |
| `score_threshold` | `Optional[float]` |
| `application_name` | `str` |


## 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`
- `ef_search`
- `score_threshold`
- `application_name`

## Methods

- [`lookup()`](https://reference.langchain.com/python/langchain-community/cache/AzureCosmosDBSemanticCache/lookup)
- [`update()`](https://reference.langchain.com/python/langchain-community/cache/AzureCosmosDBSemanticCache/update)
- [`clear()`](https://reference.langchain.com/python/langchain-community/cache/AzureCosmosDBSemanticCache/clear)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/a6a6079511ac8a5c1293337f88096b8641562e77/libs/community/langchain_community/cache.py#L1643)