import { ... } from "@langchain/core/vectorstores";Abstract class extending VectorStore that defines a contract for saving
and loading vector store instances.
The SaveableVectorStore class allows vector store implementations to
persist their data and retrieve it when needed.The format for saving and
loading data is left to the implementing subclass.
Subclasses must implement the save method to handle their custom
serialization logic, while the load method enables reconstruction of a
vector store from saved data, requiring compatible embeddings through the
EmbeddingsInterface.
Abstract class representing a vector storage system for performing similarity searches on embedded documents.
VectorStore provides methods for adding precomputed vectors or documents,
removing documents based on criteria, and performing similarity searches
with optional scoring. Subclasses are responsible for implementing specific
storage mechanisms and the exact behavior of certain abstract methods.
Class for retrieving documents from a VectorStore based on vector similarity
or maximal marginal relevance (MMR).
VectorStoreRetriever extends BaseRetriever, implementing methods for
adding documents to the underlying vector store and performing document
retrieval with optional configurations.
VectorStoreRetriever
Interface defining the structure and operations of a vector store, which facilitates the storage, retrieval, and similarity search of document vectors.
VectorStoreInterface provides methods for adding, deleting, and searching
documents based on vector embeddings, including support for similarity
search with optional filtering and relevance-based retrieval.
Interface for a retriever that uses a vector store to store and retrieve document embeddings. This retriever interface allows for adding documents to the underlying vector store and conducting retrieval operations.
VectorStoreRetrieverInterface extends BaseRetrieverInterface to provide
document retrieval capabilities based on vector similarity.
VectorStoreRetrieverInterface
Options for configuring a maximal marginal relevance (MMR) search.
MMR search optimizes for both similarity to the query and diversity among the results, balancing the retrieval of relevant documents with variation in the content returned.
Fields:
fetchK (optional): The initial number of documents to retrieve from the
vector store before applying the MMR algorithm. This larger set provides a
pool of documents from which the algorithm can select the most diverse
results based on relevance to the query.
filter (optional): A filter of type FilterType to refine the search
results, allowing additional conditions to target specific subsets
of documents.
k: The number of documents to return in the final results. This is the
primary count of documents that are most relevant to the query.
lambda (optional): A value between 0 and 1 that determines the balance
between relevance and diversity:
lambda of 0 emphasizes diversity, maximizing content variation.lambda of 1 emphasizes similarity to the query, focusing on relevance.
Values between 0 and 1 provide a mix of relevance and diversity.Input configuration options for creating a VectorStoreRetriever instance.
This type combines properties from BaseRetrieverInput with specific settings
for the VectorStoreRetriever, including options for similarity or maximal
marginal relevance (MMR) search types.
Fields:
callbacks (optional): An array of callback functions that handle various
events during retrieval, such as logging, error handling, or progress updates.
tags (optional): An array of strings used to add contextual tags to
retrieval operations, allowing for easier categorization and tracking.
metadata (optional): A record of key-value pairs to store additional
contextual information for retrieval operations, which can be useful
for logging or auditing purposes.
verbose (optional): A boolean flag that, if set to true, enables
detailed logging and output during the retrieval process. Defaults to false.
vectorStore: The VectorStore instance implementing VectorStoreInterface
that will be used for document storage and retrieval.
k (optional): Specifies the number of documents to retrieve per search
query. Defaults to 4 if not specified.
filter (optional): A filter of type FilterType (defined by the vector store)
to refine the set of documents returned, allowing for targeted search results.
searchType: Determines the type of search to perform:
"similarity": Executes a similarity search, retrieving documents based purely
on vector similarity to the query."mmr": Executes a maximal marginal relevance (MMR) search, balancing similarity
and diversity in the search results.searchKwargs (optional): Used only if searchType is "mmr", this object
provides additional options for MMR search, including:
fetchK: Specifies the number of documents to initially fetch before applying
the MMR algorithm, providing a pool from which the most diverse results are selected.lambda: A diversity parameter, where 0 emphasizes diversity and 1 emphasizes
relevance to the query. Values between 0 and 1 provide a balance of relevance and diversity.Options for configuring a maximal marginal relevance (MMR) search
when using the VectorStoreRetriever.
These parameters control how the MMR algorithm balances relevance to the query and diversity among the retrieved documents.
Fields:
fetchK (optional): Specifies the initial number of documents to fetch
before applying the MMR algorithm. This larger set provides a pool of
documents from which the algorithm can select the most diverse results
based on relevance to the query.
lambda (optional): A value between 0 and 1 that determines the balance
between relevance and diversity:
lambda of 0 maximizes diversity among the results, prioritizing varied content.lambda of 1 maximizes similarity to the query, prioritizing relevance.
Values between 0 and 1 provide a mix of relevance and diversity.