/** * LangChain integration for CyborgDB JavaScript SDK. * * This module provides a LangChain VectorStore implementation for CyborgDB, * enabling seamless integration with LangChain applications. * * Requirements: * npm install @langchain/core */ import type { Document, DocumentInterface } from "@langchain/core/documents"; import type { EmbeddingsInterface } from "@langchain/core/embeddings"; import { VectorStore } from "@langchain/core/vectorstores"; import type { FilterExpression } from "../../types"; export interface CyborgVectorStoreConfig { indexName: string; /** * 32-byte key (base64 string or Uint8Array). Optional when `kmsName` * references a real-provider KMS registry entry (the service manages the * key). Required for legacy indexes and `provider: none` slots. */ indexKey?: string | Uint8Array; /** Optional name of a `kms.registry` entry in the service config. */ kmsName?: string; apiKey: string; baseUrl: string; embedding: EmbeddingsInterface; dimension?: number; metric?: "cosine" | "euclidean" | "squared_euclidean"; verifySsl?: boolean; } export declare class CyborgVectorStore extends VectorStore { FilterType: Record; private client; private index?; private indexName; private indexKey?; private kmsName?; private dimension?; private metric; _vectorstoreType(): string; constructor(embeddings: EmbeddingsInterface, config: CyborgVectorStoreConfig); /** * Generate a secure 32-byte key for use with CyborgDB indexes. * * @throws If the host provides no Web Crypto implementation. */ static generateKey(): Uint8Array; /** * Generate a unique ID for documents. */ private generateId; /** * Initialize or load the CyborgDB index. */ private initializeIndex; /** * Add texts to the vector store. */ addTexts(texts: string[], metadatas?: object[] | object, options?: { ids?: string[]; }): Promise; /** * Add documents to the vector store. */ addDocuments(documents: DocumentInterface[], options?: { ids?: string[]; }): Promise; /** * Add vectors directly to the vector store. */ addVectors(vectors: number[][], documents: DocumentInterface[], options?: { ids?: string[]; }): Promise; /** * Delete documents from the vector store. */ delete(params: { ids?: string[]; }): Promise; /** * Retrieve documents by their IDs. */ get(ids: string[]): Promise; /** * List all document IDs in the vector store. */ listIds(filter?: FilterExpression): Promise; /** * Search for documents similar to the query. */ similaritySearch(query: string, k?: number, filter?: this["FilterType"], _callbacks?: any): Promise; /** * Search for documents with similarity scores. */ similaritySearchWithScore(query: string, k?: number, filter?: this["FilterType"], _callbacks?: any): Promise<[DocumentInterface, number][]>; /** * Search for documents similar to an embedding vector. */ similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[DocumentInterface, number][]>; /** * Convert distance to similarity score [0, 1]. */ private normalizeScore; /** * Maximal Marginal Relevance search - balances similarity with diversity. * * @param query - The query string * @param options - MMR search options including k, fetchK, lambda, and filter * @returns Promise of documents selected by maximal marginal relevance */ maxMarginalRelevanceSearch(query: string, options: { k: number; fetchK?: number; lambda?: number; filter?: Record; }): Promise; /** * Calculate cosine similarity between two vectors. */ private cosineSimilarity; /** * Create a vector store from texts. */ static fromTexts(texts: string[], metadatas: object[] | object, embeddings: EmbeddingsInterface, config: CyborgVectorStoreConfig): Promise; /** * Create a vector store from documents. */ static fromDocuments(docs: DocumentInterface[], embeddings: EmbeddingsInterface, config: CyborgVectorStoreConfig): Promise; /** * Create a vector store from an existing index. */ static fromExistingIndex(embeddings: EmbeddingsInterface, config: CyborgVectorStoreConfig): Promise; }