UNPKG

@langchain/community

Version:
1 lines • 7.67 kB
{"version":3,"file":"faiss.d.ts","names":["IndexFlatL2","NameRegistry","Parser","EmbeddingsInterface","SaveableVectorStore","Document","SynchronousInMemoryDocstore","FaissLibArgs","Record","FaissStore","Promise"],"sources":["../../src/vectorstores/faiss.d.ts"],"sourcesContent":["import type { IndexFlatL2 } from \"faiss-node\";\nimport type { NameRegistry, Parser } from \"pickleparser\";\nimport type { EmbeddingsInterface } from \"@langchain/core/embeddings\";\nimport { SaveableVectorStore } from \"@langchain/core/vectorstores\";\nimport { Document } from \"@langchain/core/documents\";\nimport { SynchronousInMemoryDocstore } from \"@langchain/classic/stores/doc/in_memory\";\n/**\n * Interface for the arguments required to initialize a FaissStore\n * instance.\n */\nexport interface FaissLibArgs {\n docstore?: SynchronousInMemoryDocstore;\n index?: IndexFlatL2;\n mapping?: Record<number, string>;\n}\n/**\n * A class that wraps the FAISS (Facebook AI Similarity Search) vector\n * database for efficient similarity search and clustering of dense\n * vectors.\n */\nexport declare class FaissStore extends SaveableVectorStore {\n _index?: IndexFlatL2;\n _mapping: Record<number, string>;\n docstore: SynchronousInMemoryDocstore;\n args: FaissLibArgs;\n _vectorstoreType(): string;\n getMapping(): Record<number, string>;\n getDocstore(): SynchronousInMemoryDocstore;\n constructor(embeddings: EmbeddingsInterface, args: FaissLibArgs);\n /**\n * Adds an array of Document objects to the store.\n * @param documents An array of Document objects.\n * @returns A Promise that resolves when the documents have been added.\n */\n addDocuments(documents: Document[], options?: {\n ids?: string[];\n }): Promise<string[]>;\n get index(): IndexFlatL2;\n private set index(value);\n /**\n * Adds an array of vectors and their corresponding Document objects to\n * the store.\n * @param vectors An array of vectors.\n * @param documents An array of Document objects corresponding to the vectors.\n * @returns A Promise that resolves with an array of document IDs when the vectors and documents have been added.\n */\n addVectors(vectors: number[][], documents: Document[], options?: {\n ids?: string[];\n }): Promise<string[]>;\n /**\n * Performs a similarity search in the vector store using a query vector\n * and returns the top k results along with their scores.\n * @param query A query vector.\n * @param k The number of top results to return.\n * @returns A Promise that resolves with an array of tuples, each containing a Document and its corresponding score.\n */\n similaritySearchVectorWithScore(query: number[], k: number): Promise<[Document<Record<string, any>>, number][]>;\n /**\n * Saves the current state of the FaissStore to a specified directory.\n * @param directory The directory to save the state to.\n * @returns A Promise that resolves when the state has been saved.\n */\n save(directory: string): Promise<void>;\n /**\n * Method to delete documents.\n * @param params Object containing the IDs of the documents to delete.\n * @returns A promise that resolves when the deletion is complete.\n */\n delete(params: {\n ids: string[];\n }): Promise<void>;\n /**\n * Merges the current FaissStore with another FaissStore.\n * @param targetIndex The FaissStore to merge with.\n * @returns A Promise that resolves with an array of document IDs when the merge is complete.\n */\n mergeFrom(targetIndex: FaissStore): Promise<string[]>;\n /**\n * Loads a FaissStore from a specified directory.\n * @param directory The directory to load the FaissStore from.\n * @param embeddings An Embeddings object.\n * @returns A Promise that resolves with a new FaissStore instance.\n */\n static load(directory: string, embeddings: EmbeddingsInterface): Promise<FaissStore>;\n static loadFromPython(directory: string, embeddings: EmbeddingsInterface): Promise<FaissStore>;\n /**\n * Creates a new FaissStore from an array of texts, their corresponding\n * metadata, and an Embeddings object.\n * @param texts An array of texts.\n * @param metadatas An array of metadata corresponding to the texts, or a single metadata object to be used for all texts.\n * @param embeddings An Embeddings object.\n * @param dbConfig An optional configuration object for the document store.\n * @returns A Promise that resolves with a new FaissStore instance.\n */\n static fromTexts(texts: string[], metadatas: object[] | object, embeddings: EmbeddingsInterface, dbConfig?: {\n docstore?: SynchronousInMemoryDocstore;\n }): Promise<FaissStore>;\n /**\n * Creates a new FaissStore from an array of Document objects and an\n * Embeddings object.\n * @param docs An array of Document objects.\n * @param embeddings An Embeddings object.\n * @param dbConfig An optional configuration object for the document store.\n * @returns A Promise that resolves with a new FaissStore instance.\n */\n static fromDocuments(docs: Document[], embeddings: EmbeddingsInterface, dbConfig?: {\n docstore?: SynchronousInMemoryDocstore;\n }): Promise<FaissStore>;\n /**\n * Creates a new FaissStore from an existing FaissStore and an Embeddings\n * object.\n * @param targetIndex An existing FaissStore.\n * @param embeddings An Embeddings object.\n * @param dbConfig An optional configuration object for the document store.\n * @returns A Promise that resolves with a new FaissStore instance.\n */\n static fromIndex(targetIndex: FaissStore, embeddings: EmbeddingsInterface, dbConfig?: {\n docstore?: SynchronousInMemoryDocstore;\n }): Promise<FaissStore>;\n static importFaiss(): Promise<{\n IndexFlatL2: typeof IndexFlatL2;\n }>;\n static importPickleparser(): Promise<{\n Parser: typeof Parser;\n NameRegistry: typeof NameRegistry;\n }>;\n}\n//# sourceMappingURL=faiss.d.ts.map"],"mappings":";;;;;;;;;;;AAUA;;AAEYA,UAFKO,YAAAA,CAELP;EACEQ,QAAAA,CAAAA,EAFCF,2BAEDE;EAAM,KAAA,CAAA,EADRR,WACQ;EAOCS,OAAAA,CAAAA,EAPPD,MAOiB,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;AAQHL,cARPM,UAAAA,SAAmBL,mBAAAA,CAQZD;EAA2BI,MAAAA,CAAAA,EAP1CP,WAO0CO;EAM3BF,QAAAA,EAZdG,MAYcH,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAEpBK,QAAAA,EAbMJ,2BAaNI;EACSV,IAAAA,EAbPO,YAaOP;EAS8BK,gBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAEvCK,UAAAA,CAAAA,CAAAA,EAtBUF,MAsBVE,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAQ2EF,WAAAA,CAAAA,CAAAA,EA7BhEF,2BA6BgEE;EAATH,WAAAA,CAAAA,UAAAA,EA5B9CF,mBA4B8CE,EAAAA,IAAAA,EA5BnBE,YA4BmBF;EAATK;;;;;EA2BlBP,YAAAA,CAAAA,SAAAA,EAjDnBE,QAiDmBF,EAAAA,EAAAA,OAAsBO,CAAtBP,EAAAA;IAA8BM,GAAAA,CAAAA,EAAAA,MAAAA,EAAAA;EAARC,CAAAA,CAAAA,EA/C7DA,OA+C6DA,CAAAA,MAAAA,E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