import { MaxMarginalRelevanceSearchOptions, VectorStore } from "@langchain/core/vectorstores"; import { Document, DocumentInterface } from "@langchain/core/documents"; import { Container, ContainerRequest, CosmosClient, DatabaseRequest, FullTextPolicy, FullTextPolicy as FullTextPolicy$1, IndexingPolicy, SqlQuerySpec, VectorEmbeddingPolicy, VectorIndex } from "@azure/cosmos"; import { TokenCredential } from "@azure/identity"; import { EmbeddingsInterface } from "@langchain/core/embeddings"; //#region src/azure_cosmosdb_nosql.d.ts /** Azure Cosmos DB for NoSQL search types. */ declare const AzureCosmosDBNoSQLSearchType: { /** Vector similarity search. */readonly Vector: "vector"; /** Vector search with score threshold filtering. */ readonly VectorScoreThreshold: "vector_score_threshold"; /** Full-text search only (preview feature). */ readonly FullTextSearch: "full_text_search"; /** Full-text search with BM25 ranking (preview feature). */ readonly FullTextRanking: "full_text_ranking"; /** Hybrid search combining vector and full-text search with RRF (preview feature). */ readonly Hybrid: "hybrid"; /** Hybrid search with score threshold filtering (preview feature). */ readonly HybridScoreThreshold: "hybrid_score_threshold"; }; /** Azure Cosmos DB for NoSQL search type. */ type AzureCosmosDBNoSQLSearchType = (typeof AzureCosmosDBNoSQLSearchType)[keyof typeof AzureCosmosDBNoSQLSearchType]; /** * Full-text rank filter item for full-text ranking queries. * Each item specifies a field to search and the search text. */ interface AzureCosmosDBNoSQLFullTextRankFilter { /** The field to search. */ searchField: string; /** The search text. */ searchText: string; } /** * Projection mapping for custom field selection. * Maps field names to their aliases in the query results. */ type ProjectionMapping = Record; /** Azure Cosmos DB for NoSQL query filter. */ type AzureCosmosDBNoSQLQueryFilter = string | SqlQuerySpec; /** Azure Cosmos DB for NoSQL filter type. */ type AzureCosmosDBNoSQLFilterType = { /** * SQL filter clause to add to the search query. * @example 'WHERE c.category = "cars"' */ filterClause?: AzureCosmosDBNoSQLQueryFilter; /** Determines whether or not to include the embeddings in the search results. */ includeEmbeddings?: boolean; /** Search type override for this query. Takes precedence over the default search type. */ searchType?: AzureCosmosDBNoSQLSearchType; /** * Full-text rank filter for full-text ranking queries. * Each item specifies a field to search and the search text. */ fullTextRankFilter?: AzureCosmosDBNoSQLFullTextRankFilter[]; /** * Projection mapping for custom field selection. * Maps field names to their paths in the document. */ projectionMapping?: ProjectionMapping; /** * Offset and limit clause for pagination. * @example 'OFFSET 10 LIMIT 20' */ offsetLimit?: string; /** * Weights for hybrid search RRF (Reciprocal Rank Fusion). * Typically two values: [vectorWeight, fullTextWeight]. */ weights?: number[]; /** * Score threshold for filtering results. * Only results with a score >= threshold are returned. */ threshold?: number; }; /** Azure Cosmos DB for NoSQL Delete Parameters. */ type AzureCosmosDBNoSqlDeleteParams = { /** List of IDs for the documents to be removed. */readonly ids?: string | string[]; /** SQL query to select the documents to be removed. */ readonly filter?: AzureCosmosDBNoSQLQueryFilter; }; /** Azure Cosmos DB for NoSQL database creation options. */ type AzureCosmosDBNoSqlCreateDatabaseOptions = Partial>; /** Azure Cosmos DB for NoSQL container creation options. */ type AzureCosmosDBNoSqlCreateContainerOptions = Partial>; /** * Initialization options for the Azure CosmosDB for NoSQL database and container. * * Note that if you provide multiple vector embeddings in the vectorEmbeddingPolicy, * the first one will be used for creating documents and searching. */ interface AzureCosmosDBNoSQLInitOptions { readonly vectorEmbeddingPolicy?: VectorEmbeddingPolicy; readonly indexingPolicy?: IndexingPolicy; /** * Full-text policy for the container (preview feature). * Required when fullTextSearchEnabled is true. */ readonly fullTextPolicy?: FullTextPolicy; readonly createContainerOptions?: AzureCosmosDBNoSqlCreateContainerOptions; readonly createDatabaseOptions?: AzureCosmosDBNoSqlCreateDatabaseOptions; } /** * Configuration options for the `AzureCosmosDBNoSQLVectorStore` constructor. */ interface AzureCosmosDBNoSQLConfig extends AzureCosmosDBNoSQLInitOptions { /** Pre-configured CosmosClient instance. If provided, connectionString and endpoint are ignored. */ readonly client?: CosmosClient; /** Cosmos DB connection string. */ readonly connectionString?: string; /** Cosmos DB endpoint URL (used with credentials for Azure AD authentication). */ readonly endpoint?: string; /** Azure credential for authentication (defaults to DefaultAzureCredential). */ readonly credentials?: TokenCredential; /** Database name. Defaults to "vectorSearchDB". */ readonly databaseName?: string; /** Container name. Defaults to "vectorSearchContainer". */ readonly containerName?: string; /** Document field name for the text content. Defaults to "text". */ readonly textKey?: string; /** Document field name for the metadata. Defaults to "metadata". */ readonly metadataKey?: string; /** * Enable full-text search capabilities (preview feature). * When enabled, fullTextPolicy and appropriate indexingPolicy must be configured. */ readonly fullTextSearchEnabled?: boolean; /** Table alias used in Cosmos DB SQL queries. Defaults to "c". */ readonly tableAlias?: string; /** * Default search type to use when no search type is specified in the filter. * Defaults to "vector". */ readonly defaultSearchType?: AzureCosmosDBNoSQLSearchType; } /** * Azure Cosmos DB for NoSQL vector store. * To use this, you should have both: * - the `@azure/cosmos` NPM package installed * - a connection string associated with a NoSQL instance * * You do not need to create a database or container, it will be created * automatically. * * @example * ```typescript * const vectorStore = new AzureCosmosDBNoSQLVectorStore( * new OpenAIEmbeddings(), * { * databaseName: "mydb", * containerName: "vectors", * } * ); * await vectorStore.addDocuments(docs); * const results = await vectorStore.similaritySearch("query", 4); * ``` */ declare class AzureCosmosDBNoSQLVectorStore extends VectorStore { FilterType: AzureCosmosDBNoSQLFilterType; get lc_secrets(): { [key: string]: string; }; private initPromise?; private readonly client; private container; private readonly textKey; private readonly metadataKey; private embeddingKey; private readonly fullTextSearchEnabled; private readonly tableAlias; private readonly fullTextPolicy?; private readonly defaultSearchType; /** * Initializes the AzureCosmosDBNoSQLVectorStore. * Connects the client to the database and creates the container if needed. * @returns A promise that resolves when the AzureCosmosDBNoSQLVectorStore has been initialized. */ initialize: () => Promise; _vectorstoreType(): string; constructor(embeddings: EmbeddingsInterface, dbConfig: AzureCosmosDBNoSQLConfig); /** * Removes specified documents from the AzureCosmosDBNoSQLVectorStore. * If no IDs or filter are specified, all documents will be removed. * @param params Parameters for the delete operation. * @returns A promise that resolves when the documents have been removed. */ delete(params?: AzureCosmosDBNoSqlDeleteParams): Promise; /** * Gets the underlying Cosmos DB container. * Useful for performing direct operations on the container. * @returns The Cosmos DB container instance. */ getContainer(): Container; /** * Method for adding vectors to the AzureCosmosDBNoSQLVectorStore. * @param vectors Vectors to be added. * @param documents Corresponding documents to be added. * @returns A promise that resolves to the added documents IDs. */ addVectors(vectors: number[][], documents: DocumentInterface[]): Promise; /** * Method for adding documents to the AzureCosmosDBNoSQLVectorStore. It first converts * the documents to texts and then adds them as vectors. * @param documents The documents to add. * @returns A promise that resolves to the added documents IDs. */ addDocuments(documents: DocumentInterface[]): Promise; /** * Performs a similarity search on the vectors stored in the container. * Routes to the appropriate search implementation based on the search type * specified in the filter or the default search type configured for the vector store. * @param queryVector Query vector for the similarity search. * @param k Number of nearest neighbors to return. Defaults to 4. * @param filter Optional filter options for the documents. * @returns Promise that resolves to a list of documents and their corresponding similarity scores. */ similaritySearchVectorWithScore(queryVector: number[], k?: number, filter?: this["FilterType"] | undefined): Promise<[Document, number][]>; /** * Return documents selected using the maximal marginal relevance. * Maximal marginal relevance optimizes for similarity to the query AND * diversity among selected documents. * @param query Text to look up documents similar to. * @param options.k Number of documents to return. * @param options.fetchK Number of documents to fetch before passing to * the MMR algorithm. Defaults to 20. * @param options.lambda Number between 0 and 1 that determines the * degree of diversity among the results, where 0 corresponds to maximum * diversity and 1 to minimum diversity. Defaults to 0.5. * @returns List of documents selected by maximal marginal relevance. */ maxMarginalRelevanceSearch(query: string, options: MaxMarginalRelevanceSearchOptions): Promise; /** * Return documents selected using the maximal marginal relevance from a vector. * Maximal marginal relevance optimizes for similarity to the query AND * diversity among selected documents. * @param queryEmbedding Query embedding vector. * @param options.k Number of documents to return. * @param options.fetchK Number of documents to fetch before passing to * the MMR algorithm. Defaults to 20. * @param options.lambda Number between 0 and 1 that determines the * degree of diversity among the results, where 0 corresponds to maximum * diversity and 1 to minimum diversity. Defaults to 0.5. * @returns List of documents selected by maximal marginal relevance. */ maxMarginalRelevanceSearchByVector(queryEmbedding: number[], options: MaxMarginalRelevanceSearchOptions): Promise; private init; private vectorSearchWithScore; private hybridSearchWithScore; private hybridSearchWithScoreThreshold; private vectorSearchWithScoreThreshold; private fullTextRanking; private fullTextSearch; /** * Constructs a Cosmos DB SQL query string and parameters based on the search type and options. * Builds the complete SQL query including SELECT clause, projections, FROM clause, * WHERE conditions, ORDER BY clauses (with RRF for hybrid/full-text), and pagination. * * @param k The maximum number of results to return. * @param searchType The type of search to perform. * @param options Configuration options including embeddings, filters, projections, and search-specific parameters. * @returns An object containing the constructed SQL query string and an array of parameters. */ private constructQuery; /** * Generates the SELECT clause projection fields for the SQL query. */ private generateProjectionFields; /** * Builds the parameter array for the SQL query. */ private buildParameters; /** * Extracts the text content from a query result item. * Uses custom projection mapping alias if provided, otherwise falls back to the default textKey. */ private extractTextFromItem; /** * Populates metadata object from query result item fields. * Adds projected field aliases to metadata, or defaults to adding the document id. */ private populateMetadataFromItem; private executeQuery; /** * Static method to create an instance of AzureCosmosDBNoSQLVectorStore from a * list of texts. It first converts the texts to vectors and then adds * them to the collection. * @param texts List of texts to be converted to vectors. * @param metadatas Metadata for the texts. * @param embeddings Embeddings to be used for conversion. * @param dbConfig Database configuration for Azure Cosmos DB for NoSQL. * @returns Promise that resolves to a new instance of AzureCosmosDBNoSQLVectorStore. */ static fromTexts(texts: string[], metadatas: object[] | object, embeddings: EmbeddingsInterface, dbConfig: AzureCosmosDBNoSQLConfig): Promise; /** * Static method to create an instance of AzureCosmosDBNoSQLVectorStore from a * list of documents. It first converts the documents to vectors and then * adds them to the collection. * @param docs List of documents to be converted to vectors. * @param embeddings Embeddings to be used for conversion. * @param dbConfig Database configuration for Azure Cosmos DB for NoSQL. * @returns Promise that resolves to a new instance of AzureCosmosDBNoSQLVectorStore. */ static fromDocuments(docs: Document[], embeddings: EmbeddingsInterface, dbConfig: AzureCosmosDBNoSQLConfig): Promise; } //#endregion export { AzureCosmosDBNoSQLConfig, AzureCosmosDBNoSQLFilterType, AzureCosmosDBNoSQLFullTextRankFilter, AzureCosmosDBNoSQLInitOptions, AzureCosmosDBNoSQLQueryFilter, AzureCosmosDBNoSQLSearchType, AzureCosmosDBNoSQLVectorStore, AzureCosmosDBNoSqlCreateContainerOptions, AzureCosmosDBNoSqlCreateDatabaseOptions, AzureCosmosDBNoSqlDeleteParams, type FullTextPolicy$1 as FullTextPolicy, ProjectionMapping, type VectorIndex }; //# sourceMappingURL=azure_cosmosdb_nosql.d.ts.map