AzureCosmosDBMongoDBVectorStore
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:76
Azure Cosmos DB for MongoDB vCore vector store. To use this, you should have both:
- the
mongodbNPM package installed - a connection string associated with a MongoDB VCore Cluster
You do not need to create a database or collection, it will be created automatically.
You also need an index on the collection, which is by default be created
automatically using the createIndex method.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AzureCosmosDBMongoDBVectorStore(
init):AzureCosmosDBMongoDBVectorStore
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:107
Parameters
Section titled “Parameters”Partial<AzureCosmosDBMongoDBVectorStore> & object & VectorStoreBaseParams
Returns
Section titled “Returns”AzureCosmosDBMongoDBVectorStore
Overrides
Section titled “Overrides”Properties
Section titled “Properties”storesText
Section titled “storesText”storesText:
boolean=true
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:77
Overrides
Section titled “Overrides”flatMetadata
Section titled “flatMetadata”flatMetadata:
boolean=true
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:78
dbName
Section titled “dbName”dbName:
string
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:80
collectionName
Section titled “collectionName”collectionName:
string
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:82
indexedMetadataFields
Section titled “indexedMetadataFields”indexedMetadataFields:
string[]
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:84
mongodbClient
Section titled “mongodbClient”mongodbClient:
MongoClient
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:89
The used MongoClient. If not given, a new MongoClient is created based on the MONGODB_URI env variable.
indexName
Section titled “indexName”indexName:
string
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:91
embeddingKey
Section titled “embeddingKey”embeddingKey:
string
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:93
idKey:
string
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:95
textKey
Section titled “textKey”textKey:
string
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:97
metadataKey
Section titled “metadataKey”metadataKey:
string
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:99
indexOptions
Section titled “indexOptions”indexOptions:
AzureCosmosDBMongoDBIndexOptions
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:101
embedModel
Section titled “embedModel”embedModel:
BaseEmbedding
Defined in: packages/core/src/vector-store/index.ts:128
Inherited from
Section titled “Inherited from”isEmbeddingQuery?
Section titled “isEmbeddingQuery?”
optionalisEmbeddingQuery:boolean
Defined in: packages/core/src/vector-store/index.ts:130
Inherited from
Section titled “Inherited from”BaseVectorStore.isEmbeddingQuery
Methods
Section titled “Methods”client()
Section titled “client()”client():
MongoClient
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:145
Returns
Section titled “Returns”MongoClient
Overrides
Section titled “Overrides”ensureCollection()
Section titled “ensureCollection()”ensureCollection():
Promise<Collection<Document>>
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:149
Returns
Section titled “Returns”Promise<Collection<Document>>
add(
nodes):Promise<string[]>
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:161
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<string[]>
Overrides
Section titled “Overrides”delete()
Section titled “delete()”delete(
refDocId,deleteOptions?):Promise<void>
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:200
Deletes all nodes from the collection that belong to the given document.
Parameters
Section titled “Parameters”refDocId
Section titled “refDocId”string
Reference document ID - all nodes with this ref_doc_id will be deleted.
deleteOptions?
Section titled “deleteOptions?”object
Additional delete options.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the documents have been removed.
Overrides
Section titled “Overrides”query()
Section titled “query()”query(
query,options):Promise<VectorStoreQueryResult>
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:210
Parameters
Section titled “Parameters”options
Section titled “options”AzureCosmosDBMongoDBQueryOptions
Returns
Section titled “Returns”Promise<VectorStoreQueryResult>
Overrides
Section titled “Overrides”createIndex()
Section titled “createIndex()”createIndex(
dimensions,indexType,similarity):Promise<void>
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:289
Creates an index on the collection with the specified index name during instance construction.
Setting the numLists parameter correctly is important for achieving good accuracy and performance. Since the vector store uses IVF as the indexing strategy, you should create the index only after you have loaded a large enough sample documents to ensure that the centroids for the respective buckets are faily distributed.
As for the compression, the following options are available:
- “half” - half precision compression for HNSW and IVF indexes
- “pq” - product quantization compression for DiskANN indexes More information on the compression options can be found in the: https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/product-quantization
Parameters
Section titled “Parameters”dimensions
Section titled “dimensions”Number of dimensions for vector similarity. The maximum number of supported dimensions is 2000. If no number is provided, it will be determined automatically by embedding a short text.
number | undefined
indexType
Section titled “indexType”Index Type for Mongo vCore index.
"hnsw" | "ivf" | "diskann"
similarity
Section titled “similarity”AzureCosmosDBMongoDBSimilarityType = AzureCosmosDBMongoDBSimilarityType.COS
Similarity metric to use with the IVF index. Possible options are:
- CosmosDBSimilarityType.COS (cosine distance)
- CosmosDBSimilarityType.L2 (Euclidean distance)
- CosmosDBSimilarityType.IP (inner product)
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the index has been created.
checkIndexExists()
Section titled “checkIndexExists()”checkIndexExists():
Promise<boolean>
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:354
Checks if the specified index name during instance construction exists on the collection.
Returns
Section titled “Returns”Promise<boolean>
A promise that resolves to a boolean indicating if the index exists.
deleteIndex()
Section titled “deleteIndex()”deleteIndex(
indexName):Promise<void>
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:364
Deletes the index specified during instance construction if it exists.
Parameters
Section titled “Parameters”indexName
Section titled “indexName”string
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the index has been deleted.
exists()
Section titled “exists()”exists(
refDocId):Promise<boolean>
Defined in: packages/providers/storage/azure/src/vectorStore/AzureCosmosDBMongoVectorStore.ts:373
Check if any nodes exist for the given document reference ID. Used for de-duplication during ingestion.
Parameters
Section titled “Parameters”refDocId
Section titled “refDocId”string
The reference document ID to check
Returns
Section titled “Returns”Promise<boolean>
true if any nodes with this ref_doc_id exist