id
stringlengths
14
15
text
stringlengths
49
2.47k
source
stringlengths
61
166
68b354b073e2-8
lucene_filter: the Lucene algorithm decides whether to perform an exact k-NN search with pre-filtering or an approximate search with modified post-filtering. (deprecated, use efficient_filter) efficient_filter: the Lucene Engine or Faiss Engine decides whether to perform an exact k-NN search with pre-filtering or an approximate search with modified post-filtering. Optional Args for Script Scoring Search:search_type: “script_scoring”; default: “approximate_search” space_type: “l2”, “l1”, “linf”, “cosinesimil”, “innerproduct”, “hammingbit”; default: “l2” pre_filter: script_score query to pre-filter documents before identifying nearest neighbors; default: {“match_all”: {}} Optional Args for Painless Scripting Search:search_type: “painless_scripting”; default: “approximate_search” space_type: “l2Squared”, “l1Norm”, “cosineSimilarity”; default: “l2Squared” pre_filter: script_score query to pre-filter documents before identifying nearest neighbors; default: {“match_all”: {}} similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar. Parameters query – input text
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.opensearch_vector_search.OpenSearchVectorSearch.html
68b354b073e2-9
0 is dissimilar, 1 is most similar. Parameters query – input text k – Number of Documents to return. Defaults to 4. **kwargs – kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of Tuples of (doc, similarity_score) similarity_search_with_score(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]][source]¶ Return docs and it’s scores most similar to query. By default, supports Approximate Search. Also supports Script Scoring and Painless Scripting. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents along with its scores most similar to the query. Optional Args:same as similarity_search Examples using OpenSearchVectorSearch¶ OpenSearch
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.opensearch_vector_search.OpenSearchVectorSearch.html
a0ca72ca7669-0
langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch¶ class langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch(collection: Collection[MongoDBDocumentType], embedding: Embeddings, *, index_name: str = 'default', text_key: str = 'text', embedding_key: str = 'embedding')[source]¶ Wrapper around MongoDB Atlas Vector Search. To use, you should have both: - the pymongo python package installed - a connection string associated with a MongoDB Atlas Cluster having deployed an Atlas Search index Example from langchain.vectorstores import MongoDBAtlasVectorSearch from langchain.embeddings.openai import OpenAIEmbeddings from pymongo import MongoClient mongo_client = MongoClient("<YOUR-CONNECTION-STRING>") collection = mongo_client["<db_name>"]["<collection_name>"] embeddings = OpenAIEmbeddings() vectorstore = MongoDBAtlasVectorSearch(collection, embeddings) Parameters collection – MongoDB collection to add the texts to. embedding – Text embedding model to use. text_key – MongoDB field that will contain the text for each document. embedding_key – MongoDB field that will contain the embedding for each document. index_name – Name of the Atlas Search index. Attributes embeddings Access the query embedding object if available. Methods __init__(collection, embedding, *[, ...]) param collection MongoDB collection to add the texts to. aadd_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. aadd_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. add_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. add_texts(texts[, metadatas])
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html
a0ca72ca7669-1
add_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. afrom_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. afrom_texts(texts, embedding[, metadatas]) Return VectorStore initialized from texts and embeddings. amax_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. amax_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. as_retriever(**kwargs) Return VectorStoreRetriever initialized from this VectorStore. asearch(query, search_type, **kwargs) Return docs most similar to query using specified search type. asimilarity_search(query[, k]) Return docs most similar to query. asimilarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. asimilarity_search_with_relevance_scores(query) Return docs most similar to query. delete([ids]) Delete by vector ID or other criteria. from_connection_string(connection_string, ...) from_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_texts(texts, embedding[, metadatas, ...]) Construct MongoDBAtlasVectorSearch wrapper from raw documents. max_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. max_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. search(query, search_type, **kwargs) Return docs most similar to query using specified search type. similarity_search(query[, k, pre_filter, ...]) Return MongoDB documents most similar to query.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html
a0ca72ca7669-2
Return MongoDB documents most similar to query. similarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query, *[, k, ...]) Return MongoDB documents most similar to query, along with scores. __init__(collection: Collection[MongoDBDocumentType], embedding: Embeddings, *, index_name: str = 'default', text_key: str = 'text', embedding_key: str = 'embedding')[source]¶ Parameters collection – MongoDB collection to add the texts to. embedding – Text embedding model to use. text_key – MongoDB field that will contain the text for each document. embedding_key – MongoDB field that will contain the embedding for each document. index_name – Name of the Atlas Search index. async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str]¶ Run more texts through the embeddings and add to the vectorstore. add_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str]
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html
a0ca72ca7669-3
Returns List of IDs of the added texts. Return type List[str] add_texts(texts: Iterable[str], metadatas: Optional[List[Dict[str, Any]]] = None, **kwargs: Any) → List[source]¶ Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. Returns List of ids from adding the texts into the vectorstore. async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → VST¶ Return VectorStore initialized from texts and embeddings. async amax_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. async amax_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. as_retriever(**kwargs: Any) → VectorStoreRetriever¶ Return VectorStoreRetriever initialized from this VectorStore. Parameters search_type (Optional[str]) – Defines the type of search that the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html
a0ca72ca7669-4
“similarity_score_threshold”. search_kwargs (Optional[Dict]) – Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata Returns Retriever class for VectorStore. Return type VectorStoreRetriever Examples: # Retrieve more documents with higher diversity # Useful if your dataset has many similar documents docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25} ) # Fetch more documents for the MMR algorithm to consider # But only return the top 5 docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50} ) # Only retrieve documents that have a relevance score # Above a certain threshold docsearch.as_retriever( search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8} ) # Only get the single most similar document from the dataset docsearch.as_retriever(search_kwargs={'k': 1}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever( search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}} ) async asearch(query: str, search_type: str, **kwargs: Any) → List[Document]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html
a0ca72ca7669-5
Return docs most similar to query using specified search type. async asimilarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to query. async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs most similar to query. delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool]¶ Delete by vector ID or other criteria. Parameters ids – List of ids to delete. **kwargs – Other keyword arguments that subclasses might use. Returns True if deletion is successful, False otherwise, None if not implemented. Return type Optional[bool] classmethod from_connection_string(connection_string: str, namespace: str, embedding: Embeddings, **kwargs: Any) → MongoDBAtlasVectorSearch[source]¶ classmethod from_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, collection: Optional[Collection[MongoDBDocumentType]] = None, **kwargs: Any) → MongoDBAtlasVectorSearch[source]¶ Construct MongoDBAtlasVectorSearch wrapper from raw documents. This is a user-friendly interface that: Embeds documents. Adds the documents to a provided MongoDB Atlas Vector Search index(Lucene) This is intended to be a quick way to get started. Example
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html
a0ca72ca7669-6
This is intended to be a quick way to get started. Example max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, pre_filter: Optional[dict] = None, post_filter_pipeline: Optional[List[Dict]] = None, **kwargs: Any) → List[Document][source]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Optional Number of Documents to return. Defaults to 4. fetch_k – Optional Number of Documents to fetch before passing to MMR algorithm. Defaults to 20. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. pre_filter – Optional Dictionary of argument(s) to prefilter on document fields. post_filter_pipeline – Optional Pipeline of MongoDB aggregation stages following the knnBeta search. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html
a0ca72ca7669-7
lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. search(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. similarity_search(query: str, k: int = 4, pre_filter: Optional[dict] = None, post_filter_pipeline: Optional[List[Dict]] = None, **kwargs: Any) → List[Document][source]¶ Return MongoDB documents most similar to query. Use the knnBeta Operator available in MongoDB Atlas Search This feature is in early access and available only for evaluation purposes, to validate functionality, and to gather feedback from a small closed group of early access users. It is not recommended for production deployments as we may introduce breaking changes. For more: https://www.mongodb.com/docs/atlas/atlas-search/knn-beta Parameters query – Text to look up documents similar to. k – Optional Number of Documents to return. Defaults to 4. pre_filter – Optional Dictionary of argument(s) to prefilter on document fields. post_filter_pipeline – Optional Pipeline of MongoDB aggregation stages following the knnBeta search. Returns List of Documents most similar to the query and score for each similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query vector.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html
a0ca72ca7669-8
Returns List of Documents most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar. Parameters query – input text k – Number of Documents to return. Defaults to 4. **kwargs – kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of Tuples of (doc, similarity_score) similarity_search_with_score(query: str, *, k: int = 4, pre_filter: Optional[dict] = None, post_filter_pipeline: Optional[List[Dict]] = None) → List[Tuple[Document, float]][source]¶ Return MongoDB documents most similar to query, along with scores. Use the knnBeta Operator available in MongoDB Atlas Search This feature is in early access and available only for evaluation purposes, to validate functionality, and to gather feedback from a small closed group of early access users. It is not recommended for production deployments as we may introduce breaking changes. For more: https://www.mongodb.com/docs/atlas/atlas-search/knn-beta Parameters query – Text to look up documents similar to. k – Optional Number of Documents to return. Defaults to 4. pre_filter – Optional Dictionary of argument(s) to prefilter on document fields. post_filter_pipeline – Optional Pipeline of MongoDB aggregation stages following the knnBeta search. Returns List of Documents most similar to the query and score for each Examples using MongoDBAtlasVectorSearch¶ MongoDB Atlas
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch.html
f844cc084dd5-0
langchain.vectorstores.starrocks.has_mul_sub_str¶ langchain.vectorstores.starrocks.has_mul_sub_str(s: str, *args: Any) → bool[source]¶ Check if a string has multiple substrings. :param s: The string to check :param *args: The substrings to check for in the string Returns True if all substrings are present in the string, False otherwise Return type bool
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.starrocks.has_mul_sub_str.html
3e263ee53a25-0
langchain.vectorstores.utils.DistanceStrategy¶ class langchain.vectorstores.utils.DistanceStrategy(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶ Enumerator of the Distance strategies for calculating distances between vectors. EUCLIDEAN_DISTANCE = 'EUCLIDEAN_DISTANCE'¶ MAX_INNER_PRODUCT = 'MAX_INNER_PRODUCT'¶ DOT_PRODUCT = 'DOT_PRODUCT'¶ JACCARD = 'JACCARD'¶ COSINE = 'COSINE'¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.utils.DistanceStrategy.html
2d6add52d6ed-0
langchain.vectorstores.alibabacloud_opensearch.AlibabaCloudOpenSearchSettings¶ class langchain.vectorstores.alibabacloud_opensearch.AlibabaCloudOpenSearchSettings(endpoint: str, instance_id: str, username: str, password: str, datasource_name: str, embedding_index_name: str, field_name_mapping: Dict[str, str])[source]¶ Opensearch Client Configuration Attribute: endpoint (str) : The endpoint of opensearch instance, You can find it from the console of Alibaba Cloud OpenSearch. instance_id (str) : The identify of opensearch instance, You can find it from the console of Alibaba Cloud OpenSearch. datasource_name (str): The name of the data source specified when creating it. username (str) : The username specified when purchasing the instance. password (str) : The password specified when purchasing the instance. embedding_index_name (str) : The name of the vector attribute specified when configuring the instance attributes. field_name_mapping (Dict) : Using field name mapping between opensearch vector store and opensearch instance configuration table field names: { ‘id’: ‘The id field name map of index document.’, ‘document’: ‘The text field name map of index document.’, ‘embedding’: ‘In the embedding field of the opensearch instance, the values must be in float16 multivalue type and separated by commas.’, ‘metadata_field_x’: ‘Metadata field mapping includes the mapped field name and operator in the mapping value, separated by a comma between the mapped field name and the operator.’, } Attributes field_name_mapping endpoint instance_id username password datasource_name embedding_index_name Methods __init__(endpoint, instance_id, username, ...)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.alibabacloud_opensearch.AlibabaCloudOpenSearchSettings.html
2d6add52d6ed-1
Methods __init__(endpoint, instance_id, username, ...) __init__(endpoint: str, instance_id: str, username: str, password: str, datasource_name: str, embedding_index_name: str, field_name_mapping: Dict[str, str]) → None[source]¶ Examples using AlibabaCloudOpenSearchSettings¶ Alibaba Cloud OpenSearch
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.alibabacloud_opensearch.AlibabaCloudOpenSearchSettings.html
de1f81c95712-0
langchain.vectorstores.awadb.AwaDB¶ class langchain.vectorstores.awadb.AwaDB(table_name: str = 'langchain_awadb', embedding: Optional[Embeddings] = None, log_and_data_dir: Optional[str] = None, client: Optional[awadb.Client] = None, **kwargs: Any)[source]¶ Interface implemented by AwaDB vector stores. Initialize with AwaDB client.If table_name is not specified, a random table name of _DEFAULT_TABLE_NAME + last segment of uuid would be created automatically. Parameters table_name – Name of the table created, default _DEFAULT_TABLE_NAME. embedding – Optional Embeddings initially set. log_and_data_dir – Optional the root directory of log and data. client – Optional AwaDB client. kwargs – Any possible extend parameters in the future. Returns None. Attributes embeddings Access the query embedding object if available. Methods __init__([table_name, embedding, ...]) Initialize with AwaDB client. aadd_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. aadd_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. add_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. add_texts(texts[, metadatas, is_duplicate_texts]) Run more texts through the embeddings and add to the vectorstore. afrom_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. afrom_texts(texts, embedding[, metadatas]) Return VectorStore initialized from texts and embeddings. amax_marginal_relevance_search(query[, k, ...])
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-1
amax_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. amax_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. as_retriever(**kwargs) Return VectorStoreRetriever initialized from this VectorStore. asearch(query, search_type, **kwargs) Return docs most similar to query using specified search type. asimilarity_search(query[, k]) Return docs most similar to query. asimilarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. asimilarity_search_with_relevance_scores(query) Return docs most similar to query. create_table(table_name, **kwargs) Create a new table. delete([ids]) Delete the documents which have the specified ids. from_documents(documents[, embedding, ...]) Create an AwaDB vectorstore from a list of documents. from_texts(texts[, embedding, metadatas, ...]) Create an AwaDB vectorstore from a raw documents. get([ids, text_in_page_content, ...]) Return docs according ids. get_current_table(**kwargs) Get the current table. list_tables(**kwargs) List all the tables created by the client. load_local(table_name, **kwargs) Load the local specified table. max_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. max_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. search(query, search_type, **kwargs) Return docs most similar to query using specified search type. similarity_search(query[, k, ...]) Return docs most similar to query.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-2
similarity_search(query[, k, ...]) Return docs most similar to query. similarity_search_by_vector([embedding, k, ...]) Return docs most similar to embedding vector. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query[, k, ...]) The most k similar documents and scores of the specified query. update(ids, texts[, metadatas]) Update the documents which have the specified ids. use(table_name, **kwargs) Use the specified table. __init__(table_name: str = 'langchain_awadb', embedding: Optional[Embeddings] = None, log_and_data_dir: Optional[str] = None, client: Optional[awadb.Client] = None, **kwargs: Any) → None[source]¶ Initialize with AwaDB client.If table_name is not specified, a random table name of _DEFAULT_TABLE_NAME + last segment of uuid would be created automatically. Parameters table_name – Name of the table created, default _DEFAULT_TABLE_NAME. embedding – Optional Embeddings initially set. log_and_data_dir – Optional the root directory of log and data. client – Optional AwaDB client. kwargs – Any possible extend parameters in the future. Returns None. async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-3
Run more texts through the embeddings and add to the vectorstore. add_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, is_duplicate_texts: Optional[bool] = None, **kwargs: Any) → List[str][source]¶ Run more texts through the embeddings and add to the vectorstore. :param texts: Iterable of strings to add to the vectorstore. :param metadatas: Optional list of metadatas associated with the texts. :param is_duplicate_texts: Optional whether to duplicate texts. Defaults to True. :param kwargs: any possible extend parameters in the future. Returns List of ids from adding the texts into the vectorstore. async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → VST¶ Return VectorStore initialized from texts and embeddings. async amax_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-4
Return docs selected using the maximal marginal relevance. async amax_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. as_retriever(**kwargs: Any) → VectorStoreRetriever¶ Return VectorStoreRetriever initialized from this VectorStore. Parameters search_type (Optional[str]) – Defines the type of search that the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”. search_kwargs (Optional[Dict]) – Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata Returns Retriever class for VectorStore. Return type VectorStoreRetriever Examples: # Retrieve more documents with higher diversity # Useful if your dataset has many similar documents docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25} ) # Fetch more documents for the MMR algorithm to consider # But only return the top 5 docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50} )
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-5
search_kwargs={'k': 5, 'fetch_k': 50} ) # Only retrieve documents that have a relevance score # Above a certain threshold docsearch.as_retriever( search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8} ) # Only get the single most similar document from the dataset docsearch.as_retriever(search_kwargs={'k': 1}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever( search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}} ) async asearch(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. async asimilarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to query. async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs most similar to query. create_table(table_name: str, **kwargs: Any) → bool[source]¶ Create a new table. delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool][source]¶ Delete the documents which have the specified ids. Parameters ids – The ids of the embedding vectors. **kwargs – Other keyword arguments that subclasses might use. Returns True if deletion is successful. False otherwise, None if not implemented. Return type
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-6
True if deletion is successful. False otherwise, None if not implemented. Return type Optional[bool] classmethod from_documents(documents: List[Document], embedding: Optional[Embeddings] = None, table_name: str = 'langchain_awadb', log_and_data_dir: Optional[str] = None, client: Optional[awadb.Client] = None, **kwargs: Any) → AwaDB[source]¶ Create an AwaDB vectorstore from a list of documents. If a log_and_data_dir specified, the table will be persisted there. Parameters documents (List[Document]) – List of documents to add to the vectorstore. embedding (Optional[Embeddings]) – Embedding function. Defaults to None. table_name (str) – Name of the table to create. log_and_data_dir (Optional[str]) – Directory to persist the table. client (Optional[awadb.Client]) – AwaDB client. Any – Any possible parameters in the future Returns AwaDB vectorstore. Return type AwaDB classmethod from_texts(texts: List[str], embedding: Optional[Embeddings] = None, metadatas: Optional[List[dict]] = None, table_name: str = 'langchain_awadb', log_and_data_dir: Optional[str] = None, client: Optional[awadb.Client] = None, **kwargs: Any) → AwaDB[source]¶ Create an AwaDB vectorstore from a raw documents. Parameters texts (List[str]) – List of texts to add to the table. embedding (Optional[Embeddings]) – Embedding function. Defaults to None. metadatas (Optional[List[dict]]) – List of metadatas. Defaults to None. table_name (str) – Name of the table to create.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-7
table_name (str) – Name of the table to create. log_and_data_dir (Optional[str]) – Directory of logging and persistence. client (Optional[awadb.Client]) – AwaDB client Returns AwaDB vectorstore. Return type AwaDB get(ids: Optional[List[str]] = None, text_in_page_content: Optional[str] = None, meta_filter: Optional[dict] = None, not_include_fields: Optional[Set[str]] = None, limit: Optional[int] = None, **kwargs: Any) → Dict[str, Document][source]¶ Return docs according ids. Parameters ids – The ids of the embedding vectors. text_in_page_content – Filter by the text in page_content of Document. meta_filter – Filter by any metadata of the document. not_include_fields – Not pack the specified fields of each document. limit – The number of documents to return. Defaults to 5. Optional. Returns Documents which satisfy the input conditions. get_current_table(**kwargs: Any) → str[source]¶ Get the current table. list_tables(**kwargs: Any) → List[str][source]¶ List all the tables created by the client. load_local(table_name: str, **kwargs: Any) → bool[source]¶ Load the local specified table. Parameters table_name – Table name kwargs – Any possible extend parameters in the future. Returns Success or failure of loading the local specified table max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, text_in_page_content: Optional[str] = None, meta_filter: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶ Return docs selected using the maximal marginal relevance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-8
Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. text_in_page_content – Filter by the text in page_content of Document. meta_filter (Optional[dict]) – Filter by metadata. Defaults to None. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, text_in_page_content: Optional[str] = None, meta_filter: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. text_in_page_content – Filter by the text in page_content of Document. meta_filter (Optional[dict]) – Filter by metadata. Defaults to None. Returns List of Documents selected by maximal marginal relevance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-9
Returns List of Documents selected by maximal marginal relevance. search(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. similarity_search(query: str, k: int = 4, text_in_page_content: Optional[str] = None, meta_filter: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶ Return docs most similar to query. Parameters query – Text query. k – The maximum number of documents to return. text_in_page_content – Filter by the text in page_content of Document. meta_filter (Optional[dict]) – Filter by metadata. Defaults to None. `{"color" (E.g.) – ”red”, “price”: 4.20}`. Optional. `{"max_price" (E.g.) – 15.66, “min_price”: 4.20}` field (price is the metadata) – filter (means range) – `{"maxe_price" (E.g.) – 15.66, “mine_price”: 4.20}` field – filter – kwargs – Any possible extend parameters in the future. Returns Returns the k most similar documents to the specified text query. similarity_search_by_vector(embedding: Optional[List[float]] = None, k: int = 4, text_in_page_content: Optional[str] = None, meta_filter: Optional[dict] = None, not_include_fields_in_metadata: Optional[Set[str]] = None, **kwargs: Any) → List[Document][source]¶ Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-10
k – Number of Documents to return. Defaults to 4. text_in_page_content – Filter by the text in page_content of Document. meta_filter – Filter by metadata. Defaults to None. not_incude_fields_in_metadata – Not include meta fields of each document. Returns List of Documents which are the most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar. Parameters query – input text k – Number of Documents to return. Defaults to 4. **kwargs – kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of Tuples of (doc, similarity_score) similarity_search_with_score(query: str, k: int = 4, text_in_page_content: Optional[str] = None, meta_filter: Optional[dict] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶ The most k similar documents and scores of the specified query. Parameters query – Text query. k – The k most similar documents to the text query. text_in_page_content – Filter by the text in page_content of Document. meta_filter – Filter by metadata. Defaults to None. kwargs – Any possible extend parameters in the future. Returns The k most similar documents to the specified text query. 0 is dissimilar, 1 is the most similar.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
de1f81c95712-11
0 is dissimilar, 1 is the most similar. update(ids: List[str], texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str][source]¶ Update the documents which have the specified ids. Parameters ids – The id list of the updating embedding vector. texts – The texts of the updating documents. metadatas – The metadatas of the updating documents. Returns the ids of the updated documents. use(table_name: str, **kwargs: Any) → bool[source]¶ Use the specified table. Don’t know the tables, please invoke list_tables. Examples using AwaDB¶ AwaDB
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.awadb.AwaDB.html
2e966e8663a5-0
langchain.vectorstores.usearch.USearch¶ class langchain.vectorstores.usearch.USearch(embedding: Embeddings, index: Any, docstore: Docstore, ids: List[str])[source]¶ Wrapper around USearch vector database. To use, you should have the usearch python package installed. Initialize with necessary components. Attributes embeddings Access the query embedding object if available. Methods __init__(embedding, index, docstore, ids) Initialize with necessary components. aadd_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. aadd_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. add_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. add_texts(texts[, metadatas, ids]) Run more texts through the embeddings and add to the vectorstore. afrom_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. afrom_texts(texts, embedding[, metadatas]) Return VectorStore initialized from texts and embeddings. amax_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. amax_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. as_retriever(**kwargs) Return VectorStoreRetriever initialized from this VectorStore. asearch(query, search_type, **kwargs) Return docs most similar to query using specified search type. asimilarity_search(query[, k]) Return docs most similar to query. asimilarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.usearch.USearch.html
2e966e8663a5-1
Return docs most similar to embedding vector. asimilarity_search_with_relevance_scores(query) Return docs most similar to query. delete([ids]) Delete by vector ID or other criteria. from_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_texts(texts, embedding[, metadatas, ...]) Construct USearch wrapper from raw documents. This is a user friendly interface that: 1. Embeds documents. 2. Creates an in memory docstore 3. Initializes the USearch database This is intended to be a quick way to get started. max_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. max_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. search(query, search_type, **kwargs) Return docs most similar to query using specified search type. similarity_search(query[, k]) Return docs most similar to query. similarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query[, k]) Return docs most similar to query. __init__(embedding: Embeddings, index: Any, docstore: Docstore, ids: List[str])[source]¶ Initialize with necessary components. async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str]
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.usearch.USearch.html
2e966e8663a5-2
Returns List of IDs of the added texts. Return type List[str] async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str]¶ Run more texts through the embeddings and add to the vectorstore. add_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] add_texts(texts: Iterable[str], metadatas: Optional[List[Dict]] = None, ids: Optional[ndarray] = None, **kwargs: Any) → List[str][source]¶ Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. ids – Optional list of unique IDs. Returns List of ids from adding the texts into the vectorstore. async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → VST¶ Return VectorStore initialized from texts and embeddings. async amax_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.usearch.USearch.html
2e966e8663a5-3
Return docs selected using the maximal marginal relevance. async amax_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. as_retriever(**kwargs: Any) → VectorStoreRetriever¶ Return VectorStoreRetriever initialized from this VectorStore. Parameters search_type (Optional[str]) – Defines the type of search that the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”. search_kwargs (Optional[Dict]) – Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata Returns Retriever class for VectorStore. Return type VectorStoreRetriever Examples: # Retrieve more documents with higher diversity # Useful if your dataset has many similar documents docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25} ) # Fetch more documents for the MMR algorithm to consider # But only return the top 5 docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50} )
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.usearch.USearch.html
2e966e8663a5-4
search_kwargs={'k': 5, 'fetch_k': 50} ) # Only retrieve documents that have a relevance score # Above a certain threshold docsearch.as_retriever( search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8} ) # Only get the single most similar document from the dataset docsearch.as_retriever(search_kwargs={'k': 1}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever( search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}} ) async asearch(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. async asimilarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to query. async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs most similar to query. delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool]¶ Delete by vector ID or other criteria. Parameters ids – List of ids to delete. **kwargs – Other keyword arguments that subclasses might use. Returns True if deletion is successful, False otherwise, None if not implemented. Return type Optional[bool] classmethod from_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.usearch.USearch.html
2e966e8663a5-5
Return VectorStore initialized from documents and embeddings. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[Dict]] = None, ids: Optional[ndarray] = None, metric: str = 'cos', **kwargs: Any) → USearch[source]¶ Construct USearch wrapper from raw documents. This is a user friendly interface that: Embeds documents. Creates an in memory docstore Initializes the USearch database This is intended to be a quick way to get started. Example from langchain.vectorstores import USearch from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() usearch = USearch.from_texts(texts, embeddings) max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.usearch.USearch.html
2e966e8663a5-6
Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. search(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. similarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document][source]¶ Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query. similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar. Parameters query – input text k – Number of Documents to return. Defaults to 4.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.usearch.USearch.html
2e966e8663a5-7
query – input text k – Number of Documents to return. Defaults to 4. **kwargs – kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of Tuples of (doc, similarity_score) similarity_search_with_score(query: str, k: int = 4) → List[Tuple[Document, float]][source]¶ Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of documents most similar to the query with distance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.usearch.USearch.html
f670d4db206f-0
langchain.vectorstores.cassandra.Cassandra¶ class langchain.vectorstores.cassandra.Cassandra(embedding: Embeddings, session: Session, keyspace: str, table_name: str, ttl_seconds: Optional[int] = None)[source]¶ Wrapper around Cassandra embeddings platform. There is no notion of a default table name, since each embedding function implies its own vector dimension, which is part of the schema. Example from langchain.vectorstores import Cassandra from langchain.embeddings.openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings() session = ... keyspace = 'my_keyspace' vectorstore = Cassandra(embeddings, session, keyspace, 'my_doc_archive') Attributes embeddings Access the query embedding object if available. Methods __init__(embedding, session, keyspace, ...) aadd_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. aadd_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. add_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. add_texts(texts[, metadatas, ids, ...]) Run more texts through the embeddings and add to the vectorstore. afrom_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. afrom_texts(texts, embedding[, metadatas]) Return VectorStore initialized from texts and embeddings. amax_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. amax_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. as_retriever(**kwargs)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
f670d4db206f-1
Return docs selected using the maximal marginal relevance. as_retriever(**kwargs) Return VectorStoreRetriever initialized from this VectorStore. asearch(query, search_type, **kwargs) Return docs most similar to query using specified search type. asimilarity_search(query[, k]) Return docs most similar to query. asimilarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. asimilarity_search_with_relevance_scores(query) Return docs most similar to query. clear() Empty the collection. delete([ids]) Delete by vector IDs. delete_by_document_id(document_id) delete_collection() Just an alias for clear (to better align with other VectorStore implementations). from_documents(documents, embedding[, ...]) Create a Cassandra vectorstore from a document list. from_texts(texts, embedding[, metadatas, ...]) Create a Cassandra vectorstore from raw texts. max_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param query: Text to look up documents similar to. :param k: Number of Documents to return. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm. :param lambda_mult: Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Optional. max_marginal_relevance_search_by_vector(...)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
f670d4db206f-2
max_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param embedding: Embedding to look up documents similar to. :param k: Number of Documents to return. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm. :param lambda_mult: Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. search(query, search_type, **kwargs) Return docs most similar to query using specified search type. similarity_search(query[, k]) Return docs most similar to query. similarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query[, k]) Run similarity search with distance. similarity_search_with_score_by_vector(embedding) Return docs most similar to embedding vector. similarity_search_with_score_id(query[, k]) similarity_search_with_score_id_by_vector(...) Return docs most similar to embedding vector. __init__(embedding: Embeddings, session: Session, keyspace: str, table_name: str, ttl_seconds: Optional[int] = None) → None[source]¶ async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str]
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
f670d4db206f-3
Returns List of IDs of the added texts. Return type List[str] async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str]¶ Run more texts through the embeddings and add to the vectorstore. add_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, batch_size: int = 16, ttl_seconds: Optional[int] = None, **kwargs: Any) → List[str][source]¶ Run more texts through the embeddings and add to the vectorstore. Parameters texts (Iterable[str]) – Texts to add to the vectorstore. metadatas (Optional[List[dict]], optional) – Optional list of metadatas. ids (Optional[List[str]], optional) – Optional list of IDs. batch_size (int) – Number of concurrent requests to send to the server. ttl_seconds (Optional[int], optional) – Optional time-to-live for the added texts. Returns List of IDs of the added texts. Return type List[str] async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → VST¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
f670d4db206f-4
Return VectorStore initialized from texts and embeddings. async amax_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. async amax_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. as_retriever(**kwargs: Any) → VectorStoreRetriever¶ Return VectorStoreRetriever initialized from this VectorStore. Parameters search_type (Optional[str]) – Defines the type of search that the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”. search_kwargs (Optional[Dict]) – Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata Returns Retriever class for VectorStore. Return type VectorStoreRetriever Examples: # Retrieve more documents with higher diversity # Useful if your dataset has many similar documents docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25} )
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
f670d4db206f-5
) # Fetch more documents for the MMR algorithm to consider # But only return the top 5 docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50} ) # Only retrieve documents that have a relevance score # Above a certain threshold docsearch.as_retriever( search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8} ) # Only get the single most similar document from the dataset docsearch.as_retriever(search_kwargs={'k': 1}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever( search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}} ) async asearch(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. async asimilarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to query. async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs most similar to query. clear() → None[source]¶ Empty the collection. delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool][source]¶ Delete by vector IDs. Parameters ids – List of ids to delete. Returns True if deletion is successful,
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
f670d4db206f-6
Parameters ids – List of ids to delete. Returns True if deletion is successful, False otherwise, None if not implemented. Return type Optional[bool] delete_by_document_id(document_id: str) → None[source]¶ delete_collection() → None[source]¶ Just an alias for clear (to better align with other VectorStore implementations). classmethod from_documents(documents: List[Document], embedding: Embeddings, batch_size: int = 16, **kwargs: Any) → CVST[source]¶ Create a Cassandra vectorstore from a document list. No support for specifying text IDs Returns a Cassandra vectorstore. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, batch_size: int = 16, **kwargs: Any) → CVST[source]¶ Create a Cassandra vectorstore from raw texts. No support for specifying text IDs Returns a Cassandra vectorstore. max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document][source]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param query: Text to look up documents similar to. :param k: Number of Documents to return. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm. :param lambda_mult: Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Optional. Returns List of Documents selected by maximal marginal relevance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
f670d4db206f-7
Optional. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document][source]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param embedding: Embedding to look up documents similar to. :param k: Number of Documents to return. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm. :param lambda_mult: Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Returns List of Documents selected by maximal marginal relevance. search(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. similarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document][source]¶ Return docs most similar to query. similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document][source]¶ Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
f670d4db206f-8
0 is dissimilar, 1 is most similar. Parameters query – input text k – Number of Documents to return. Defaults to 4. **kwargs – kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of Tuples of (doc, similarity_score) similarity_search_with_score(query: str, k: int = 4) → List[Tuple[Document, float]][source]¶ Run similarity search with distance. similarity_search_with_score_by_vector(embedding: List[float], k: int = 4) → List[Tuple[Document, float]][source]¶ Return docs most similar to embedding vector. No support for filter query (on metadata) along with vector search. Parameters embedding (str) – Embedding to look up documents similar to. k (int) – Number of Documents to return. Defaults to 4. Returns List of (Document, score), the most similar to the query vector. similarity_search_with_score_id(query: str, k: int = 4) → List[Tuple[Document, float, str]][source]¶ similarity_search_with_score_id_by_vector(embedding: List[float], k: int = 4) → List[Tuple[Document, float, str]][source]¶ Return docs most similar to embedding vector. No support for filter query (on metadata) along with vector search. Parameters embedding (str) – Embedding to look up documents similar to. k (int) – Number of Documents to return. Defaults to 4. Returns List of (Document, score, id), the most similar to the query vector. Examples using Cassandra¶ Cassandra
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
75ce0ab48bb3-0
langchain.vectorstores.starrocks.get_named_result¶ langchain.vectorstores.starrocks.get_named_result(connection: Any, query: str) → List[dict[str, Any]][source]¶ Get a named result from a query. :param connection: The connection to the database :param query: The query to execute Returns The result of the query Return type List[dict[str, Any]]
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.starrocks.get_named_result.html
20d815e360ad-0
langchain.vectorstores.matching_engine.MatchingEngine¶ class langchain.vectorstores.matching_engine.MatchingEngine(project_id: str, index: MatchingEngineIndex, endpoint: MatchingEngineIndexEndpoint, embedding: Embeddings, gcs_client: storage.Client, gcs_bucket_name: str, credentials: Optional[Credentials] = None)[source]¶ Vertex Matching Engine implementation of the vector store. While the embeddings are stored in the Matching Engine, the embedded documents will be stored in GCS. An existing Index and corresponding Endpoint are preconditions for using this module. See usage in docs/modules/indexes/vectorstores/examples/matchingengine.ipynb Note that this implementation is mostly meant for reading if you are planning to do a real time implementation. While reading is a real time operation, updating the index takes close to one hour. Vertex Matching Engine implementation of the vector store. While the embeddings are stored in the Matching Engine, the embedded documents will be stored in GCS. An existing Index and corresponding Endpoint are preconditions for using this module. See usage in docs/modules/indexes/vectorstores/examples/matchingengine.ipynb. Note that this implementation is mostly meant for reading if you are planning to do a real time implementation. While reading is a real time operation, updating the index takes close to one hour. project_id¶ The GCS project id. index¶ The created index class. See ~:func:MatchingEngine.from_components. endpoint¶ The created endpoint class. See ~:func:MatchingEngine.from_components. embedding¶ A Embeddings that will be used for embedding the text sent. If none is sent, then the multilingual Tensorflow Universal Sentence Encoder will be used. gcs_client¶ The GCS client. gcs_bucket_name¶ The GCS bucket name.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
20d815e360ad-1
The GCS client. gcs_bucket_name¶ The GCS bucket name. credentials¶ Created GCP credentials. Type Optional Attributes embeddings Access the query embedding object if available. Methods __init__(project_id, index, endpoint, ...[, ...]) Vertex Matching Engine implementation of the vector store. aadd_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. aadd_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. add_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. add_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. afrom_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. afrom_texts(texts, embedding[, metadatas]) Return VectorStore initialized from texts and embeddings. amax_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. amax_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. as_retriever(**kwargs) Return VectorStoreRetriever initialized from this VectorStore. asearch(query, search_type, **kwargs) Return docs most similar to query using specified search type. asimilarity_search(query[, k]) Return docs most similar to query. asimilarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. asimilarity_search_with_relevance_scores(query) Return docs most similar to query. delete([ids]) Delete by vector ID or other criteria.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
20d815e360ad-2
delete([ids]) Delete by vector ID or other criteria. from_components(project_id, region, ...[, ...]) Takes the object creation out of the constructor. from_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_texts(texts, embedding[, metadatas]) Use from components instead. max_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. max_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. search(query, search_type, **kwargs) Return docs most similar to query using specified search type. similarity_search(query[, k]) Return docs most similar to query. similarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(*args, **kwargs) Run similarity search with distance. __init__(project_id: str, index: MatchingEngineIndex, endpoint: MatchingEngineIndexEndpoint, embedding: Embeddings, gcs_client: storage.Client, gcs_bucket_name: str, credentials: Optional[Credentials] = None)[source]¶ Vertex Matching Engine implementation of the vector store. While the embeddings are stored in the Matching Engine, the embedded documents will be stored in GCS. An existing Index and corresponding Endpoint are preconditions for using this module. See usage in docs/modules/indexes/vectorstores/examples/matchingengine.ipynb. Note that this implementation is mostly meant for reading if you are planning to do a real time implementation. While reading is a real time operation, updating the index takes close to one hour.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
20d815e360ad-3
operation, updating the index takes close to one hour. project_id¶ The GCS project id. index¶ The created index class. See ~:func:MatchingEngine.from_components. endpoint¶ The created endpoint class. See ~:func:MatchingEngine.from_components. embedding¶ A Embeddings that will be used for embedding the text sent. If none is sent, then the multilingual Tensorflow Universal Sentence Encoder will be used. gcs_client¶ The GCS client. gcs_bucket_name¶ The GCS bucket name. credentials¶ Created GCP credentials. Type Optional async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str]¶ Run more texts through the embeddings and add to the vectorstore. add_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str][source]¶ Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
20d815e360ad-4
Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. kwargs – vectorstore specific parameters. Returns List of ids from adding the texts into the vectorstore. async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → VST¶ Return VectorStore initialized from texts and embeddings. async amax_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. async amax_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. as_retriever(**kwargs: Any) → VectorStoreRetriever¶ Return VectorStoreRetriever initialized from this VectorStore. Parameters search_type (Optional[str]) – Defines the type of search that the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”. search_kwargs (Optional[Dict]) – Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
20d815e360ad-5
score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata Returns Retriever class for VectorStore. Return type VectorStoreRetriever Examples: # Retrieve more documents with higher diversity # Useful if your dataset has many similar documents docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25} ) # Fetch more documents for the MMR algorithm to consider # But only return the top 5 docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50} ) # Only retrieve documents that have a relevance score # Above a certain threshold docsearch.as_retriever( search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8} ) # Only get the single most similar document from the dataset docsearch.as_retriever(search_kwargs={'k': 1}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever( search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}} ) async asearch(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. async asimilarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to query.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
20d815e360ad-6
Return docs most similar to query. async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs most similar to query. delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool]¶ Delete by vector ID or other criteria. Parameters ids – List of ids to delete. **kwargs – Other keyword arguments that subclasses might use. Returns True if deletion is successful, False otherwise, None if not implemented. Return type Optional[bool] classmethod from_components(project_id: str, region: str, gcs_bucket_name: str, index_id: str, endpoint_id: str, credentials_path: Optional[str] = None, embedding: Optional[Embeddings] = None) → MatchingEngine[source]¶ Takes the object creation out of the constructor. Parameters project_id – The GCP project id. region – The default location making the API calls. It must have regional. (the same location as the GCS bucket and must be) – gcs_bucket_name – The location where the vectors will be stored in created. (order for the index to be) – index_id – The id of the created index. endpoint_id – The id of the created endpoint. credentials_path – (Optional) The path of the Google credentials on system. (the local file) – embedding – The Embeddings that will be used for texts. (embedding the) – Returns A configured MatchingEngine with the texts added to the index.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
20d815e360ad-7
Returns A configured MatchingEngine with the texts added to the index. classmethod from_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → MatchingEngine[source]¶ Use from components instead. max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
20d815e360ad-8
fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. search(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. similarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document][source]¶ Return docs most similar to query. Parameters query – The string that will be used to search for similar documents. k – The amount of neighbors that will be retrieved. Returns A list of k matching documents. similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar. Parameters query – input text k – Number of Documents to return. Defaults to 4. **kwargs – kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of Tuples of (doc, similarity_score)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
20d815e360ad-9
Returns List of Tuples of (doc, similarity_score) similarity_search_with_score(*args: Any, **kwargs: Any) → List[Tuple[Document, float]]¶ Run similarity search with distance. Examples using MatchingEngine¶ MatchingEngine
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.matching_engine.MatchingEngine.html
ef3c5bc993af-0
langchain.vectorstores.elastic_vector_search.ElasticKnnSearch¶ class langchain.vectorstores.elastic_vector_search.ElasticKnnSearch(index_name: str, embedding: Embeddings, es_connection: Optional['Elasticsearch'] = None, es_cloud_id: Optional[str] = None, es_user: Optional[str] = None, es_password: Optional[str] = None, vector_query_field: Optional[str] = 'vector', query_field: Optional[str] = 'text')[source]¶ ElasticKnnSearch is a class for performing k-nearest neighbor (k-NN) searches on text data using Elasticsearch. This class is used to create an Elasticsearch index of text data that can be searched using k-NN search. The text data is transformed into vector embeddings using a provided embedding model, and these embeddings are stored in the Elasticsearch index. index_name¶ The name of the Elasticsearch index. Type str embedding¶ The embedding model to use for transforming text data into vector embeddings. Type Embeddings es_connection¶ An existing Elasticsearch connection. Type Elasticsearch, optional es_cloud_id¶ The Cloud ID of your Elasticsearch Service deployment. Type str, optional es_user¶ The username for your Elasticsearch Service deployment. Type str, optional es_password¶ The password for your Elasticsearch Service deployment. Type str, optional vector_query_field¶ The name of the field in the Elasticsearch index that contains the vector embeddings. Type str, optional query_field¶ The name of the field in the Elasticsearch index that contains the original text data. Type str, optional Usage:>>> from embeddings import Embeddings >>> embedding = Embeddings.load('glove') >>> es_search = ElasticKnnSearch('my_index', embedding)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-1
>>> es_search = ElasticKnnSearch('my_index', embedding) >>> es_search.add_texts(['Hello world!', 'Another text']) >>> results = es_search.knn_search('Hello') [(Document(page_content='Hello world!', metadata={}), 0.9)] Attributes embeddings Access the query embedding object if available. Methods __init__(index_name, embedding[, ...]) aadd_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. aadd_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. add_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. add_texts(texts[, metadatas, model_id, ...]) Add a list of texts to the Elasticsearch index. afrom_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. afrom_texts(texts, embedding[, metadatas]) Return VectorStore initialized from texts and embeddings. amax_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. amax_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. as_retriever(**kwargs) Return VectorStoreRetriever initialized from this VectorStore. asearch(query, search_type, **kwargs) Return docs most similar to query using specified search type. asimilarity_search(query[, k]) Return docs most similar to query. asimilarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. asimilarity_search_with_relevance_scores(query) Return docs most similar to query. create_knn_index(mapping)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-2
Return docs most similar to query. create_knn_index(mapping) Create a new k-NN index in Elasticsearch. delete([ids]) Delete by vector ID or other criteria. from_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_texts(texts, embedding[, metadatas]) Create a new ElasticKnnSearch instance and add a list of texts to the knn_hybrid_search([query, k, query_vector, ...]) Perform a hybrid k-NN and text search on the Elasticsearch index. knn_search([query, k, query_vector, ...]) Perform a k-NN search on the Elasticsearch index. max_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. max_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. search(query, search_type, **kwargs) Return docs most similar to query using specified search type. similarity_search(query[, k, filter]) Pass through to knn_search similarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query[, k]) Pass through to knn_search including score __init__(index_name: str, embedding: Embeddings, es_connection: Optional['Elasticsearch'] = None, es_cloud_id: Optional[str] = None, es_user: Optional[str] = None, es_password: Optional[str] = None, vector_query_field: Optional[str] = 'vector', query_field: Optional[str] = 'text')[source]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-3
async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str]¶ Run more texts through the embeddings and add to the vectorstore. add_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] add_texts(texts: Iterable[str], metadatas: Optional[List[Dict[Any, Any]]] = None, model_id: Optional[str] = None, refresh_indices: bool = False, **kwargs: Any) → List[str][source]¶ Add a list of texts to the Elasticsearch index. Parameters texts (Iterable[str]) – The texts to add to the index. metadatas (List[Dict[Any, Any]], optional) – A list of metadata dictionaries to associate with the texts. model_id (str, optional) – The ID of the model to use for transforming the texts into vectors. refresh_indices (bool, optional) – Whether to refresh the Elasticsearch indices after adding the texts. **kwargs – Arbitrary keyword arguments. Returns A list of IDs for the added texts. async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-4
Return VectorStore initialized from documents and embeddings. async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → VST¶ Return VectorStore initialized from texts and embeddings. async amax_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. async amax_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. as_retriever(**kwargs: Any) → VectorStoreRetriever¶ Return VectorStoreRetriever initialized from this VectorStore. Parameters search_type (Optional[str]) – Defines the type of search that the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”. search_kwargs (Optional[Dict]) – Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata Returns Retriever class for VectorStore. Return type VectorStoreRetriever Examples: # Retrieve more documents with higher diversity
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-5
Return type VectorStoreRetriever Examples: # Retrieve more documents with higher diversity # Useful if your dataset has many similar documents docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25} ) # Fetch more documents for the MMR algorithm to consider # But only return the top 5 docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50} ) # Only retrieve documents that have a relevance score # Above a certain threshold docsearch.as_retriever( search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8} ) # Only get the single most similar document from the dataset docsearch.as_retriever(search_kwargs={'k': 1}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever( search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}} ) async asearch(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. async asimilarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to query. async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs most similar to query.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-6
Return docs most similar to query. create_knn_index(mapping: Dict) → None[source]¶ Create a new k-NN index in Elasticsearch. Parameters mapping (Dict) – The mapping to use for the new index. Returns None delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool]¶ Delete by vector ID or other criteria. Parameters ids – List of ids to delete. **kwargs – Other keyword arguments that subclasses might use. Returns True if deletion is successful, False otherwise, None if not implemented. Return type Optional[bool] classmethod from_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[Dict[Any, Any]]] = None, **kwargs: Any) → ElasticKnnSearch[source]¶ Create a new ElasticKnnSearch instance and add a list of texts to theElasticsearch index. Parameters texts (List[str]) – The texts to add to the index. embedding (Embeddings) – The embedding model to use for transforming the texts into vectors. metadatas (List[Dict[Any, Any]], optional) – A list of metadata dictionaries to associate with the texts. **kwargs – Arbitrary keyword arguments. Returns A new ElasticKnnSearch instance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-7
**kwargs – Arbitrary keyword arguments. Returns A new ElasticKnnSearch instance. knn_hybrid_search(query: Optional[str] = None, k: Optional[int] = 10, query_vector: Optional[List[float]] = None, model_id: Optional[str] = None, size: Optional[int] = 10, source: Optional[bool] = True, knn_boost: Optional[float] = 0.9, query_boost: Optional[float] = 0.1, fields: Optional[Union[List[Mapping[str, Any]], Tuple[Mapping[str, Any], ...]]] = None, page_content: Optional[str] = 'text') → List[Tuple[Document, float]][source]¶ Perform a hybrid k-NN and text search on the Elasticsearch index. Parameters query (str, optional) – The query text to search for. k (int, optional) – The number of nearest neighbors to return. query_vector (List[float], optional) – The query vector to search for. model_id (str, optional) – The ID of the model to use for transforming the query text into a vector. size (int, optional) – The number of search results to return. source (bool, optional) – Whether to return the source of the search results. knn_boost (float, optional) – The boost value to apply to the k-NN search results. query_boost (float, optional) – The boost value to apply to the text search results. fields (List[Mapping[str, Any]], optional) – The fields to return in the search results. page_content (str, optional) – The name of the field that contains the page content. Returns A list of tuples, where each tuple contains a Document object and a score.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-8
Returns A list of tuples, where each tuple contains a Document object and a score. knn_search(query: Optional[str] = None, k: Optional[int] = 10, query_vector: Optional[List[float]] = None, model_id: Optional[str] = None, size: Optional[int] = 10, source: Optional[bool] = True, fields: Optional[Union[List[Mapping[str, Any]], Tuple[Mapping[str, Any], ...]]] = None, page_content: Optional[str] = 'text') → List[Tuple[Document, float]][source]¶ Perform a k-NN search on the Elasticsearch index. Parameters query (str, optional) – The query text to search for. k (int, optional) – The number of nearest neighbors to return. query_vector (List[float], optional) – The query vector to search for. model_id (str, optional) – The ID of the model to use for transforming the query text into a vector. size (int, optional) – The number of search results to return. source (bool, optional) – Whether to return the source of the search results. fields (List[Mapping[str, Any]], optional) – The fields to return in the search results. page_content (str, optional) – The name of the field that contains the page content. Returns A list of tuples, where each tuple contains a Document object and a score. max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-9
among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. search(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. similarity_search(query: str, k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶ Pass through to knn_search similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
ef3c5bc993af-10
Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar. Parameters query – input text k – Number of Documents to return. Defaults to 4. **kwargs – kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of Tuples of (doc, similarity_score) similarity_search_with_score(query: str, k: int = 10, **kwargs: Any) → List[Tuple[Document, float]][source]¶ Pass through to knn_search including score Examples using ElasticKnnSearch¶ ElasticSearch
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elastic_vector_search.ElasticKnnSearch.html
4409720bb623-0
langchain.vectorstores.usearch.dependable_usearch_import¶ langchain.vectorstores.usearch.dependable_usearch_import() → Any[source]¶ Import usearch if available, otherwise raise error.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.usearch.dependable_usearch_import.html
cf9dee3fb9db-0
langchain.vectorstores.qdrant.QdrantException¶ class langchain.vectorstores.qdrant.QdrantException[source]¶ Base class for all the Qdrant related exceptions
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.qdrant.QdrantException.html
56fadbda8d16-0
langchain.vectorstores.alibabacloud_opensearch.create_metadata¶ langchain.vectorstores.alibabacloud_opensearch.create_metadata(fields: Dict[str, Any]) → Dict[str, Any][source]¶ Create metadata from fields. Parameters fields – The fields of the document. The fields must be a dict. Returns The metadata of the document. The metadata must be a dict. Return type metadata
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.alibabacloud_opensearch.create_metadata.html
7672cc63796e-0
langchain.vectorstores.pgembedding.PGEmbedding¶ class langchain.vectorstores.pgembedding.PGEmbedding(connection_string: str, embedding_function: Embeddings, collection_name: str = 'langchain', collection_metadata: Optional[dict] = None, pre_delete_collection: bool = False, logger: Optional[Logger] = None)[source]¶ VectorStore implementation using Postgres and the pg_embedding extension. pg_embedding uses sequential scan by default. but you can create a HNSW index using the create_hnsw_index method. - connection_string is a postgres connection string. - embedding_function any embedding function implementing langchain.embeddings.base.Embeddings interface. collection_name is the name of the collection to use. (default: langchain) NOTE: This is not the name of the table, but the name of the collection.The tables will be created when initializing the store (if not exists) So, make sure the user has the right permissions to create tables. distance_strategy is the distance strategy to use. (default: EUCLIDEAN) EUCLIDEAN is the euclidean distance. pre_delete_collection if True, will delete the collection if it exists.(default: False) - Useful for testing. Attributes embeddings Access the query embedding object if available. Methods __init__(connection_string, embedding_function) aadd_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. aadd_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. add_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. add_embeddings(texts, embeddings, metadatas, ...) add_texts(texts[, metadatas, ids])
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
7672cc63796e-1
add_texts(texts[, metadatas, ids]) Run more texts through the embeddings and add to the vectorstore. afrom_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. afrom_texts(texts, embedding[, metadatas]) Return VectorStore initialized from texts and embeddings. amax_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. amax_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. as_retriever(**kwargs) Return VectorStoreRetriever initialized from this VectorStore. asearch(query, search_type, **kwargs) Return docs most similar to query using specified search type. asimilarity_search(query[, k]) Return docs most similar to query. asimilarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. asimilarity_search_with_relevance_scores(query) Return docs most similar to query. connect() create_collection() create_hnsw_extension() create_hnsw_index([max_elements, dims, m, ...]) create_tables_if_not_exists() delete([ids]) Delete by vector ID or other criteria. delete_collection() drop_tables() from_documents(documents, embedding[, ...]) Return VectorStore initialized from documents and embeddings. from_embeddings(text_embeddings, embedding) from_existing_index(embedding[, ...]) from_texts(texts, embedding[, metadatas, ...]) Return VectorStore initialized from texts and embeddings. get_collection(session) get_connection_string(kwargs) max_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
7672cc63796e-2
Return docs selected using the maximal marginal relevance. max_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. search(query, search_type, **kwargs) Return docs most similar to query using specified search type. similarity_search(query[, k, filter]) Return docs most similar to query. similarity_search_by_vector(embedding[, k, ...]) Return docs most similar to embedding vector. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query[, k, filter]) Run similarity search with distance. similarity_search_with_score_by_vector(embedding) __init__(connection_string: str, embedding_function: Embeddings, collection_name: str = 'langchain', collection_metadata: Optional[dict] = None, pre_delete_collection: bool = False, logger: Optional[Logger] = None) → None[source]¶ async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str]¶ Run more texts through the embeddings and add to the vectorstore. add_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
7672cc63796e-3
Returns List of IDs of the added texts. Return type List[str] add_embeddings(texts: List[str], embeddings: List[List[float]], metadatas: List[dict], ids: List[str], **kwargs: Any) → None[source]¶ add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]¶ Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. kwargs – vectorstore specific parameters Returns List of ids from adding the texts into the vectorstore. async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → VST¶ Return VectorStore initialized from texts and embeddings. async amax_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. async amax_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. as_retriever(**kwargs: Any) → VectorStoreRetriever¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
7672cc63796e-4
as_retriever(**kwargs: Any) → VectorStoreRetriever¶ Return VectorStoreRetriever initialized from this VectorStore. Parameters search_type (Optional[str]) – Defines the type of search that the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”. search_kwargs (Optional[Dict]) – Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata Returns Retriever class for VectorStore. Return type VectorStoreRetriever Examples: # Retrieve more documents with higher diversity # Useful if your dataset has many similar documents docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25} ) # Fetch more documents for the MMR algorithm to consider # But only return the top 5 docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50} ) # Only retrieve documents that have a relevance score # Above a certain threshold docsearch.as_retriever( search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8} ) # Only get the single most similar document from the dataset docsearch.as_retriever(search_kwargs={'k': 1})
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
7672cc63796e-5
docsearch.as_retriever(search_kwargs={'k': 1}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever( search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}} ) async asearch(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. async asimilarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to query. async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs most similar to query. connect() → Connection[source]¶ create_collection() → None[source]¶ create_hnsw_extension() → None[source]¶ create_hnsw_index(max_elements: int = 10000, dims: int = 1536, m: int = 8, ef_construction: int = 16, ef_search: int = 16) → None[source]¶ create_tables_if_not_exists() → None[source]¶ delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool]¶ Delete by vector ID or other criteria. Parameters ids – List of ids to delete. **kwargs – Other keyword arguments that subclasses might use. Returns True if deletion is successful, False otherwise, None if not implemented. Return type Optional[bool] delete_collection() → None[source]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
7672cc63796e-6
Return type Optional[bool] delete_collection() → None[source]¶ drop_tables() → None[source]¶ classmethod from_documents(documents: List[Document], embedding: Embeddings, collection_name: str = 'langchain', ids: Optional[List[str]] = None, pre_delete_collection: bool = False, **kwargs: Any) → PGEmbedding[source]¶ Return VectorStore initialized from documents and embeddings. classmethod from_embeddings(text_embeddings: List[Tuple[str, List[float]]], embedding: Embeddings, metadatas: Optional[List[dict]] = None, collection_name: str = 'langchain', ids: Optional[List[str]] = None, pre_delete_collection: bool = False, **kwargs: Any) → PGEmbedding[source]¶ classmethod from_existing_index(embedding: Embeddings, collection_name: str = 'langchain', pre_delete_collection: bool = False, **kwargs: Any) → PGEmbedding[source]¶ classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, collection_name: str = 'langchain', ids: Optional[List[str]] = None, pre_delete_collection: bool = False, **kwargs: Any) → PGEmbedding[source]¶ Return VectorStore initialized from texts and embeddings. get_collection(session: Session) → Optional[CollectionStore][source]¶ classmethod get_connection_string(kwargs: Dict[str, Any]) → str[source]¶ max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
7672cc63796e-7
among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. search(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. similarity_search(query: str, k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶ Return docs most similar to query.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
7672cc63796e-8
Return docs most similar to query. similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶ Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar. Parameters query – input text k – Number of Documents to return. Defaults to 4. **kwargs – kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of Tuples of (doc, similarity_score) similarity_search_with_score(query: str, k: int = 4, filter: Optional[dict] = None) → List[Tuple[Document, float]][source]¶ Run similarity search with distance. similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None) → List[Tuple[Document, float]][source]¶ Examples using PGEmbedding¶ pg_embedding
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
2be29a71300b-0
langchain.vectorstores.utils.maximal_marginal_relevance¶ langchain.vectorstores.utils.maximal_marginal_relevance(query_embedding: ndarray, embedding_list: list, lambda_mult: float = 0.5, k: int = 4) → List[int][source]¶ Calculate maximal marginal relevance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.utils.maximal_marginal_relevance.html
da81a8eccfc9-0
langchain.vectorstores.vectara.VectaraRetriever¶ class langchain.vectorstores.vectara.VectaraRetriever[source]¶ Bases: VectorStoreRetriever Retriever class for Vectara. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input data cannot be parsed to form a valid model. param metadata: Optional[Dict[str, Any]] = None¶ Optional metadata associated with the retriever. Defaults to None This metadata will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks. You can use these to eg identify a specific instance of a retriever with its use case. param search_kwargs: dict [Optional]¶ Search params. k: Number of Documents to return. Defaults to 5. lambda_val: lexical match parameter for hybrid search. filter: Dictionary of argument(s) to filter on metadata. For example a filter can be “doc.rating > 3.0 and part.lang = ‘deu’”} see https://docs.vectara.com/docs/search-apis/sql/filter-overview for more details. n_sentence_context: number of sentences before/after the matching segment to add param search_type: str = 'similarity'¶ Type of search to perform. Defaults to “similarity”. param tags: Optional[List[str]] = None¶ Optional list of tags associated with the retriever. Defaults to None These tags will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks. You can use these to eg identify a specific instance of a retriever with its use case. param vectorstore: Vectara [Required]¶ Vectara vectorstore.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.VectaraRetriever.html
da81a8eccfc9-1
param vectorstore: Vectara [Required]¶ Vectara vectorstore. async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Add documents to vectorstore. async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, max_concurrency: Optional[int] = None) → List[Output]¶ add_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Add documents to vectorstore. add_texts(texts: List[str], metadatas: Optional[List[dict]] = None, doc_metadata: Optional[dict] = {}) → None[source]¶ Add text to the Vectara vectorstore. Parameters texts (List[str]) – The text metadatas (List[dict]) – Metadata dicts, must line up with existing store async aget_relevant_documents(query: str, *, callbacks: Callbacks = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → List[Document]¶ Asynchronously get documents relevant to a query. :param query: string to find relevant documents for :param callbacks: Callback manager or list of callbacks :param tags: Optional list of tags associated with the retriever. Defaults to None These tags will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks. Parameters metadata – Optional metadata associated with the retriever. Defaults to None This metadata will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks. Returns List of relevant documents async ainvoke(input: str, config: Optional[RunnableConfig] = None) → List[Document]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.VectaraRetriever.html
da81a8eccfc9-2
async astream(input: Input, config: Optional[RunnableConfig] = None) → AsyncIterator[Output]¶ batch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, max_concurrency: Optional[int] = None) → List[Output]¶ bind(**kwargs: Any) → Runnable[Input, Output]¶ Bind arguments to a Runnable, returning a new Runnable. classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶ Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶ Duplicate a model, optionally choose which fields to include, exclude and change. Parameters include – fields to include in new model exclude – fields to exclude from new model, as with values this takes precedence over include update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data deep – set to True to make a deep copy of the model Returns new model instance
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.VectaraRetriever.html
da81a8eccfc9-3
deep – set to True to make a deep copy of the model Returns new model instance dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) → DictStrAny¶ Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. classmethod from_orm(obj: Any) → Model¶ get_relevant_documents(query: str, *, callbacks: Callbacks = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → List[Document]¶ Retrieve documents relevant to a query. :param query: string to find relevant documents for :param callbacks: Callback manager or list of callbacks :param tags: Optional list of tags associated with the retriever. Defaults to None These tags will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks. Parameters metadata – Optional metadata associated with the retriever. Defaults to None This metadata will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks. Returns List of relevant documents invoke(input: str, config: Optional[RunnableConfig] = None) → List[Document]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.VectaraRetriever.html
da81a8eccfc9-4
json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ Generate a JSON representation of the model, include and exclude arguments as per dict(). encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps(). classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ stream(input: Input, config: Optional[RunnableConfig] = None) → Iterator[Output]¶ to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶ to_json_not_implemented() → SerializedNotImplemented¶ classmethod update_forward_refs(**localns: Any) → None¶ Try to update ForwardRefs on fields based on this Model, globalns and localns. classmethod validate(value: Any) → Model¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.VectaraRetriever.html
da81a8eccfc9-5
classmethod validate(value: Any) → Model¶ with_fallbacks(fallbacks: ~typing.Sequence[~langchain.schema.runnable.Runnable[~langchain.schema.runnable.Input, ~langchain.schema.runnable.Output]], *, exceptions_to_handle: ~typing.Tuple[~typing.Type[BaseException]] = (<class 'Exception'>,)) → RunnableWithFallbacks[Input, Output]¶ allowed_search_types: ClassVar[Collection[str]] = ('similarity', 'similarity_score_threshold', 'mmr')¶ property lc_attributes: Dict¶ Return a list of attribute names that should be included in the serialized kwargs. These attributes must be accepted by the constructor. property lc_namespace: List[str]¶ Return the namespace of the langchain object. eg. [“langchain”, “llms”, “openai”] property lc_secrets: Dict[str, str]¶ Return a map of constructor argument names to secret ids. eg. {“openai_api_key”: “OPENAI_API_KEY”} property lc_serializable: bool¶ Return whether or not the class is serializable. Examples using VectaraRetriever¶ Chat Over Documents with Vectara
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.VectaraRetriever.html
6d8dedc67eb5-0
langchain.vectorstores.clickhouse.has_mul_sub_str¶ langchain.vectorstores.clickhouse.has_mul_sub_str(s: str, *args: Any) → bool[source]¶ Check if a string contains multiple substrings. :param s: string to check. :param *args: substrings to check. Returns True if all substrings are in the string, False otherwise.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.clickhouse.has_mul_sub_str.html
b9ed41e941d4-0
langchain.vectorstores.faiss.FAISS¶ class langchain.vectorstores.faiss.FAISS(embedding_function: Callable, index: Any, docstore: Docstore, index_to_docstore_id: Dict[int, str], relevance_score_fn: Optional[Callable[[float], float]] = None, normalize_L2: bool = False, distance_strategy: DistanceStrategy = DistanceStrategy.EUCLIDEAN_DISTANCE)[source]¶ Wrapper around FAISS vector database. To use, you should have the faiss python package installed. Example from langchain import FAISS faiss = FAISS(embedding_function, index, docstore, index_to_docstore_id) Initialize with necessary components. Attributes embeddings Access the query embedding object if available. Methods __init__(embedding_function, index, ...[, ...]) Initialize with necessary components. aadd_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. aadd_texts(texts[, metadatas]) Run more texts through the embeddings and add to the vectorstore. add_documents(documents, **kwargs) Run more documents through the embeddings and add to the vectorstore. add_embeddings(text_embeddings[, metadatas, ids]) Run more texts through the embeddings and add to the vectorstore. add_texts(texts[, metadatas, ids]) Run more texts through the embeddings and add to the vectorstore. afrom_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. afrom_texts(texts, embedding[, metadatas]) Return VectorStore initialized from texts and embeddings. amax_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-1
Return docs selected using the maximal marginal relevance. amax_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. as_retriever(**kwargs) Return VectorStoreRetriever initialized from this VectorStore. asearch(query, search_type, **kwargs) Return docs most similar to query using specified search type. asimilarity_search(query[, k]) Return docs most similar to query. asimilarity_search_by_vector(embedding[, k]) Return docs most similar to embedding vector. asimilarity_search_with_relevance_scores(query) Return docs most similar to query. delete([ids]) Delete by ID. deserialize_from_bytes(serialized, ...) Deserialize FAISS index, docstore, and index_to_docstore_id from bytes. from_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_embeddings(text_embeddings, embedding) Construct FAISS wrapper from raw documents. from_texts(texts, embedding[, metadatas, ids]) Construct FAISS wrapper from raw documents. load_local(folder_path, embeddings[, index_name]) Load FAISS index, docstore, and index_to_docstore_id from disk. max_marginal_relevance_search(query[, k, ...]) Return docs selected using the maximal marginal relevance. max_marginal_relevance_search_by_vector(...) Return docs selected using the maximal marginal relevance. max_marginal_relevance_search_with_score_by_vector(...) Return docs and their similarity scores selected using the maximal marginal merge_from(target) Merge another FAISS object with the current one. save_local(folder_path[, index_name]) Save FAISS index, docstore, and index_to_docstore_id to disk. search(query, search_type, **kwargs)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-2
search(query, search_type, **kwargs) Return docs most similar to query using specified search type. serialize_to_bytes() Serialize FAISS index, docstore, and index_to_docstore_id to bytes. similarity_search(query[, k, filter, fetch_k]) Return docs most similar to query. similarity_search_by_vector(embedding[, k, ...]) Return docs most similar to embedding vector. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query[, k, ...]) Return docs most similar to query. similarity_search_with_score_by_vector(embedding) Return docs most similar to query. __init__(embedding_function: Callable, index: Any, docstore: Docstore, index_to_docstore_id: Dict[int, str], relevance_score_fn: Optional[Callable[[float], float]] = None, normalize_L2: bool = False, distance_strategy: DistanceStrategy = DistanceStrategy.EUCLIDEAN_DISTANCE)[source]¶ Initialize with necessary components. async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str]¶ Run more texts through the embeddings and add to the vectorstore. add_documents(documents: List[Document], **kwargs: Any) → List[str]¶ Run more documents through the embeddings and add to the vectorstore. Parameters
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-3
Run more documents through the embeddings and add to the vectorstore. Parameters (List[Document] (documents) – Documents to add to the vectorstore. Returns List of IDs of the added texts. Return type List[str] add_embeddings(text_embeddings: Iterable[Tuple[str, List[float]]], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]¶ Run more texts through the embeddings and add to the vectorstore. Parameters text_embeddings – Iterable pairs of string and embedding to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. ids – Optional list of unique IDs. Returns List of ids from adding the texts into the vectorstore. add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]¶ Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. ids – Optional list of unique IDs. Returns List of ids from adding the texts into the vectorstore. async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → VST¶ Return VectorStore initialized from texts and embeddings.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-4
Return VectorStore initialized from texts and embeddings. async amax_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. async amax_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[Document]¶ Return docs selected using the maximal marginal relevance. as_retriever(**kwargs: Any) → VectorStoreRetriever¶ Return VectorStoreRetriever initialized from this VectorStore. Parameters search_type (Optional[str]) – Defines the type of search that the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”. search_kwargs (Optional[Dict]) – Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata Returns Retriever class for VectorStore. Return type VectorStoreRetriever Examples: # Retrieve more documents with higher diversity # Useful if your dataset has many similar documents docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25} )
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-5
) # Fetch more documents for the MMR algorithm to consider # But only return the top 5 docsearch.as_retriever( search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50} ) # Only retrieve documents that have a relevance score # Above a certain threshold docsearch.as_retriever( search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8} ) # Only get the single most similar document from the dataset docsearch.as_retriever(search_kwargs={'k': 1}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever( search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}} ) async asearch(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. async asimilarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to query. async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶ Return docs most similar to embedding vector. async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs most similar to query. delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool][source]¶ Delete by ID. These are the IDs in the vectorstore. Parameters ids – List of ids to delete. Returns True if deletion is successful, False otherwise, None if not implemented.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-6
Returns True if deletion is successful, False otherwise, None if not implemented. Return type Optional[bool] classmethod deserialize_from_bytes(serialized: bytes, embeddings: Embeddings, **kwargs: Any) → FAISS[source]¶ Deserialize FAISS index, docstore, and index_to_docstore_id from bytes. classmethod from_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶ Return VectorStore initialized from documents and embeddings. classmethod from_embeddings(text_embeddings: List[Tuple[str, List[float]]], embedding: Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → FAISS[source]¶ Construct FAISS wrapper from raw documents. This is a user friendly interface that: Embeds documents. Creates an in memory docstore Initializes the FAISS database This is intended to be a quick way to get started. Example from langchain import FAISS from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() text_embeddings = embeddings.embed_documents(texts) text_embedding_pairs = list(zip(texts, text_embeddings)) faiss = FAISS.from_embeddings(text_embedding_pairs, embeddings) classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → FAISS[source]¶ Construct FAISS wrapper from raw documents. This is a user friendly interface that: Embeds documents. Creates an in memory docstore Initializes the FAISS database This is intended to be a quick way to get started. Example from langchain import FAISS from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings()
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-7
from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() faiss = FAISS.from_texts(texts, embeddings) classmethod load_local(folder_path: str, embeddings: Embeddings, index_name: str = 'index', **kwargs: Any) → FAISS[source]¶ Load FAISS index, docstore, and index_to_docstore_id from disk. Parameters folder_path – folder path to load index, docstore, and index_to_docstore_id from. embeddings – Embeddings to use when generating queries index_name – for saving with a specific index file name max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, Any]] = None, **kwargs: Any) → List[Document][source]¶ Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch before filtering (if needed) to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, Any]] = None, **kwargs: Any) → List[Document][source]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-8
Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch before filtering to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_with_score_by_vector(embedding: List[float], *, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, Any]] = None) → List[Tuple[Document, float]][source]¶ Return docs and their similarity scores selected using the maximal marginalrelevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch before filtering to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents and similarity scores selected by maximal marginalrelevance and score for each. merge_from(target: FAISS) → None[source]¶ Merge another FAISS object with the current one. Add the target FAISS to the current one. Parameters target – FAISS object you wish to merge into the current one Returns None.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-9
target – FAISS object you wish to merge into the current one Returns None. save_local(folder_path: str, index_name: str = 'index') → None[source]¶ Save FAISS index, docstore, and index_to_docstore_id to disk. Parameters folder_path – folder path to save index, docstore, and index_to_docstore_id to. index_name – for saving with a specific index file name search(query: str, search_type: str, **kwargs: Any) → List[Document]¶ Return docs most similar to query using specified search type. serialize_to_bytes() → bytes[source]¶ Serialize FAISS index, docstore, and index_to_docstore_id to bytes. similarity_search(query: str, k: int = 4, filter: Optional[Dict[str, Any]] = None, fetch_k: int = 20, **kwargs: Any) → List[Document][source]¶ Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter – (Optional[Dict[str, str]]): Filter by metadata. Defaults to None. fetch_k – (Optional[int]) Number of Documents to fetch before filtering. Defaults to 20. Returns List of Documents most similar to the query. similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[Dict[str, Any]] = None, fetch_k: int = 20, **kwargs: Any) → List[Document][source]¶ Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-10
k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. fetch_k – (Optional[int]) Number of Documents to fetch before filtering. Defaults to 20. Returns List of Documents most similar to the embedding. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar. Parameters query – input text k – Number of Documents to return. Defaults to 4. **kwargs – kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of Tuples of (doc, similarity_score) similarity_search_with_score(query: str, k: int = 4, filter: Optional[Dict[str, Any]] = None, fetch_k: int = 20, **kwargs: Any) → List[Tuple[Document, float]][source]¶ Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. fetch_k – (Optional[int]) Number of Documents to fetch before filtering. Defaults to 20. Returns List of documents most similar to the query text with L2 distance in float. Lower score represents more similarity.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
b9ed41e941d4-11
L2 distance in float. Lower score represents more similarity. similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[Dict[str, Any]] = None, fetch_k: int = 20, **kwargs: Any) → List[Tuple[Document, float]][source]¶ Return docs most similar to query. Parameters embedding – Embedding vector to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, Any]]) – Filter by metadata. Defaults to None. fetch_k – (Optional[int]) Number of Documents to fetch before filtering. Defaults to 20. **kwargs – kwargs to be passed to similarity search. Can include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs Returns List of documents most similar to the query text and L2 distance in float for each. Lower score represents more similarity. Examples using FAISS¶ Cohere Reranker Document Comparison FAISS Loading documents from a YouTube url AutoGPT BabyAGI User Guide BabyAGI with Tools !pip install bs4 Plug-and-Plai Custom Agent with PlugIn Retrieval Generative Agents in LangChain Ensemble Retriever Custom agent with tool retrieval Select by maximal marginal relevance (MMR)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.faiss.FAISS.html
fa0e262c586c-0
langchain.vectorstores.clickhouse.ClickhouseSettings¶ class langchain.vectorstores.clickhouse.ClickhouseSettings[source]¶ Bases: BaseSettings ClickHouse Client Configuration Attribute: clickhouse_host (str)An URL to connect to MyScale backend.Defaults to ‘localhost’. clickhouse_port (int) : URL port to connect with HTTP. Defaults to 8443. username (str) : Username to login. Defaults to None. password (str) : Password to login. Defaults to None. index_type (str): index type string. index_param (list): index build parameter. index_query_params(dict): index query parameters. database (str) : Database name to find the table. Defaults to ‘default’. table (str) : Table name to operate on. Defaults to ‘vector_table’. metric (str)Metric to compute distance,supported are (‘angular’, ‘euclidean’, ‘manhattan’, ‘hamming’, ‘dot’). Defaults to ‘angular’. https://github.com/spotify/annoy/blob/main/src/annoymodule.cc#L149-L169 column_map (Dict)Column type map to project column name onto langchainsemantics. Must have keys: text, id, vector, must be same size to number of columns. For example: .. code-block:: python {‘id’: ‘text_id’, ‘uuid’: ‘global_unique_id’ ‘embedding’: ‘text_embedding’, ‘document’: ‘text_plain’, ‘metadata’: ‘metadata_dictionary_in_json’, } Defaults to identity map. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input data cannot be parsed to form a valid model.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.clickhouse.ClickhouseSettings.html
fa0e262c586c-1
Raises ValidationError if the input data cannot be parsed to form a valid model. param column_map: Dict[str, str] = {'document': 'document', 'embedding': 'embedding', 'id': 'id', 'metadata': 'metadata', 'uuid': 'uuid'}¶ param database: str = 'default'¶ param host: str = 'localhost'¶ param index_param: Optional[Union[List, Dict]] = ["'L2Distance'", 100]¶ param index_query_params: Dict[str, str] = {}¶ param index_type: str = 'annoy'¶ param metric: str = 'angular'¶ param password: Optional[str] = None¶ param port: int = 8123¶ param table: str = 'langchain'¶ param username: Optional[str] = None¶ classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶ Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶ Duplicate a model, optionally choose which fields to include, exclude and change. Parameters include – fields to include in new model exclude – fields to exclude from new model, as with values this takes precedence over include update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.clickhouse.ClickhouseSettings.html