DenseStore
def DenseStore(
**kwargs
):A factory for built-in DenseStore instances.
Factory method to construct a DenseStore instance.
Extra kwargs passed to object instantiation.
Args: persist_location: where the vector database is stored kind: one of {chroma, elasticsearch}
Returns: DenseStore instance
Elasticsearch store with dense vector search capabilities. Extends DenseStore to provide Elasticsearch-based dense vector storage.
A dense vector store based on Chroma.
Returns True if vector store has been initialized and contains documents.
Stores instances of langchain_core.documents.base.Document in vectordb
Remove a single document with ID, id_to_delete.
Deletes all documents in a Chroma collection whose source metadata field starts with the given prefix. The source argument can either be a full path to a document or a prefix (e.g., parent folder).
Args: - source: The source value or prefix
Returns: - The number of documents deleted
Update a set of documents (doc in index with same ID will be over-written)
Resets collection and removes and stored documents
Generic query method that invokes the store’s search method. This provides a consistent interface across all store types.
Perform a semantic search of the vector DB. Returns results as LangChain Document objects.
def ingest(
source_directory:str, # path to folder containing document store
chunk_size:int=1000, # text is split to this many characters by [langchain.text_splitter.RecursiveCharacterTextSplitter](https://api.python.langchain.com/en/latest/character/langchain_text_splitters.character.RecursiveCharacterTextSplitter.html)
chunk_overlap:int=100, # character overlap between chunks in `langchain.text_splitter.RecursiveCharacterTextSplitter`
ignore_fn:Optional=None, # Optional function that accepts the file path (including file name) as input and returns `True` if file path should not be ingested.
batch_size:int=41000, # batch size used when processing documents
**kwargs
)->None:Ingests all documents in source_directory (previously-ingested documents are ignored). When retrieved, the Document objects will each have a metadata dict with the absolute path to the file in metadata["source"]. Extra kwargs fed to ingest.load_single_document.
Creating new vectorstore at /tmp/tmpmftvr854
Loading documents from tests/sample_data/ktrain_paper/
Loading new documents: 100%|██████████████████████| 1/1 [00:00<00:00, 7.85it/s]
Processing and chunking 6 new documents: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 985.74it/s]
Split into 41 chunks of text (max. 500 chars each for text; max. 2000 chars for tables)
Creating embeddings. May take some minutes...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 3.01it/s]
Ingestion complete! You can now query your documents using the LLM.ask or LLM.chat methods