id
stringlengths
14
15
text
stringlengths
44
2.47k
source
stringlengths
61
181
ee0e31c7667f-7
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, filter: Optional[Union[dict, list]] = None, predicates: Optional[Predicates] = None, **kwargs: Any) → List[Document][source]¶ Run similarity search with TimescaleVector with distance. Parameters query (str) – Query text to search for. k (int) – Number of results to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents most similar to the query. async asimilarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[Union[dict, list]] = None, predicates: Optional[Predicates] = 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.timescalevector.TimescaleVector.html
ee0e31c7667f-8
k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents most similar to the query vector. async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶ Return docs most similar to query. async asimilarity_search_with_score(query: str, k: int = 4, filter: Optional[Union[dict, list]] = None, predicates: Optional[Predicates] = None, **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. Returns List of Documents most similar to the query and score for each async asimilarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[Union[dict, list]] = None, predicates: Optional[Predicates] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶ create_index(index_type: Union[IndexType, str] = IndexType.TIMESCALE_VECTOR, **kwargs: Any) → None[source]¶ date_to_range_filter(**kwargs: Any) → Any[source]¶ delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool][source]¶ 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.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.timescalevector.TimescaleVector.html
ee0e31c7667f-9
Returns True if deletion is successful, False otherwise, None if not implemented. Return type Optional[bool] delete_by_metadata(filter: Union[Dict[str, str], List[Dict[str, str]]], **kwargs: Any) → Optional[bool][source]¶ 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] drop_index() → None[source]¶ drop_tables() → None[source]¶ 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, collection_name: str = 'langchain_store', distance_strategy: DistanceStrategy = DistanceStrategy.COSINE, ids: Optional[List[str]] = None, pre_delete_collection: bool = False, **kwargs: Any) → TimescaleVector[source]¶ Construct TimescaleVector wrapper from raw documents and pre- generated embeddings. Return VectorStore initialized from documents and embeddings. Postgres connection string is required “Either pass it as a parameter or set the TIMESCALE_SERVICE_URL environment variable. Example from langchain.vectorstores import TimescaleVector from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() text_embeddings = embeddings.embed_documents(texts) text_embedding_pairs = list(zip(texts, text_embeddings)) tvs = TimescaleVector.from_embeddings(text_embedding_pairs, embeddings)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.timescalevector.TimescaleVector.html
ee0e31c7667f-10
tvs = TimescaleVector.from_embeddings(text_embedding_pairs, embeddings) classmethod from_existing_index(embedding: Embeddings, collection_name: str = 'langchain_store', distance_strategy: DistanceStrategy = DistanceStrategy.COSINE, pre_delete_collection: bool = False, **kwargs: Any) → TimescaleVector[source]¶ Get intsance of an existing TimescaleVector store.This method will return the instance of the store without inserting any new embeddings classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, collection_name: str = 'langchain_store', distance_strategy: DistanceStrategy = DistanceStrategy.COSINE, ids: Optional[List[str]] = None, pre_delete_collection: bool = False, **kwargs: Any) → TimescaleVector[source]¶ Return VectorStore initialized from texts and embeddings. Postgres connection string is required “Either pass it as a parameter or set the TIMESCALE_SERVICE_URL environment variable. classmethod get_service_url(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. 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
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.timescalevector.TimescaleVector.html
ee0e31c7667f-11
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. classmethod service_url_from_db_params(host: str, port: int, database: str, user: str, password: str) → str[source]¶ Return connection string from database parameters. similarity_search(query: str, k: int = 4, filter: Optional[Union[dict, list]] = None, predicates: Optional[Predicates] = None, **kwargs: Any) → List[Document][source]¶ Run similarity search with TimescaleVector with distance. Parameters query (str) – Query text to search for. k (int) – Number of results to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents most similar to the query.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.timescalevector.TimescaleVector.html
ee0e31c7667f-12
Returns List of Documents most similar to the query. similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[Union[dict, list]] = None, predicates: Optional[Predicates] = 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. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. 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[Union[dict, list]] = None, predicates: Optional[Predicates] = None, **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. Returns List of Documents most similar to the query and score for each
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.timescalevector.TimescaleVector.html
ee0e31c7667f-13
Returns List of Documents most similar to the query and score for each similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[Union[dict, list]] = None, predicates: Optional[Predicates] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.timescalevector.TimescaleVector.html
f25831f9adad-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]¶ Postgres with the pg_embedding extension as a vector store. 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
f25831f9adad-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
f25831f9adad-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
f25831f9adad-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
f25831f9adad-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
f25831f9adad-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
f25831f9adad-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
f25831f9adad-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
f25831f9adad-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¶ Postgres Embedding
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.pgembedding.PGEmbedding.html
2efe35f3ec2c-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
2efe35f3ec2c-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
2efe35f3ec2c-2
the new model: you should trust this data 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¶ 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¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.clickhouse.ClickhouseSettings.html
2efe35f3ec2c-3
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¶ 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¶ Examples using ClickhouseSettings¶ ClickHouse
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.clickhouse.ClickhouseSettings.html
5d7e1a17e86a-0
langchain.vectorstores.vectara.Vectara¶ class langchain.vectorstores.vectara.Vectara(vectara_customer_id: Optional[str] = None, vectara_corpus_id: Optional[str] = None, vectara_api_key: Optional[str] = None, vectara_api_timeout: int = 60)[source]¶ Vectara API vector store. See (https://vectara.com). Example from langchain.vectorstores import Vectara vectorstore = Vectara( vectara_customer_id=vectara_customer_id, vectara_corpus_id=vectara_corpus_id, vectara_api_key=vectara_api_key ) Initialize with Vectara API. Attributes embeddings Access the query embedding object if available. Methods __init__([vectara_customer_id, ...]) Initialize with Vectara API. 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_files(files_list[, metadatas]) Vectara provides a way to add documents directly via our API where pre-processing and chunking occurs internally in an optimal way This method provides a way to use that API in LangChain add_texts(texts[, metadatas, doc_metadata]) 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.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.Vectara.html
5d7e1a17e86a-1
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_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_files(files[, embedding, metadatas]) Construct Vectara wrapper from raw documents. from_texts(texts[, embedding, metadatas]) Construct Vectara 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, lambda_val, ...]) Return Vectara documents most similar to query, along with scores. 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].
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.Vectara.html
5d7e1a17e86a-2
Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query[, k, ...]) Return Vectara documents most similar to query, along with scores. __init__(vectara_customer_id: Optional[str] = None, vectara_corpus_id: Optional[str] = None, vectara_api_key: Optional[str] = None, vectara_api_timeout: int = 60)[source]¶ Initialize with Vectara API. 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_files(files_list: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str][source]¶ Vectara provides a way to add documents directly via our API where pre-processing and chunking occurs internally in an optimal way This method provides a way to use that API in LangChain Parameters files_list – Iterable of strings, each representing a local file path.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.Vectara.html
5d7e1a17e86a-3
Parameters files_list – Iterable of strings, each representing a local file path. Files could be text, HTML, PDF, markdown, doc/docx, ppt/pptx, etc. see API docs for full list metadatas – Optional list of metadatas associated with each file Returns List of ids associated with each of the files indexed add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, doc_metadata: Optional[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. metadatas – Optional list of metadatas associated with the texts. doc_metadata – optional metadata for the document This function indexes all the input text strings in the Vectara corpus as a single Vectara document, where each input text is considered a “section” and the metadata are associated with each section. if ‘doc_metadata’ is provided, it is associated with the Vectara document. Returns document ID of the document added 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.vectara.Vectara.html
5d7e1a17e86a-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) → VectaraRetriever[source]¶ 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.vectara.Vectara.html
5d7e1a17e86a-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. 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.vectara.Vectara.html
5d7e1a17e86a-6
Return VectorStore initialized from documents and embeddings. classmethod from_files(files: List[str], embedding: Optional[Embeddings] = None, metadatas: Optional[List[dict]] = None, **kwargs: Any) → Vectara[source]¶ Construct Vectara wrapper from raw documents. This is intended to be a quick way to get started. .. rubric:: Example from langchain.vectorstores import Vectara vectara = Vectara.from_files( files_list, vectara_customer_id=customer_id, vectara_corpus_id=corpus_id, vectara_api_key=api_key, ) classmethod from_texts(texts: List[str], embedding: Optional[Embeddings] = None, metadatas: Optional[List[dict]] = None, **kwargs: Any) → Vectara[source]¶ Construct Vectara wrapper from raw documents. This is intended to be a quick way to get started. .. rubric:: Example from langchain.vectorstores import Vectara vectara = Vectara.from_texts( texts, vectara_customer_id=customer_id, vectara_corpus_id=corpus_id, vectara_api_key=api_key, ) 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
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.Vectara.html
5d7e1a17e86a-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. 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 = 5, lambda_val: float = 0.025, filter: Optional[str] = None, n_sentence_context: int = 2, **kwargs: Any) → List[Document][source]¶ Return Vectara documents most similar to query, along with scores. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 5. filter – Dictionary of argument(s) to filter on metadata. For example a
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.Vectara.html
5d7e1a17e86a-8
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, defaults to 2 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. **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 = 5, lambda_val: float = 0.025, filter: Optional[str] = None, score_threshold: Optional[float] = None, n_sentence_context: int = 2, **kwargs: Any) → List[Tuple[Document, float]][source]¶ Return Vectara documents most similar to query, along with scores. Parameters
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.Vectara.html
5d7e1a17e86a-9
Return Vectara documents most similar to query, along with scores. Parameters query – Text to look up documents similar to. 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. score_threshold – minimal score threshold for the result. If defined, results with score less than this value will be filtered out. n_sentence_context – number of sentences before/after the matching segment to add, defaults to 2 Returns List of Documents most similar to the query and score for each. Examples using Vectara¶ Vectara Chat Over Documents with Vectara Vectara Text Generation
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.vectara.Vectara.html
69df14cbb4a5-0
langchain.vectorstores.zilliz.Zilliz¶ class langchain.vectorstores.zilliz.Zilliz(embedding_function: Embeddings, collection_name: str = 'LangChainCollection', connection_args: Optional[dict[str, Any]] = None, consistency_level: str = 'Session', index_params: Optional[dict] = None, search_params: Optional[dict] = None, drop_old: Optional[bool] = False, *, primary_field: str = 'pk', text_field: str = 'text', vector_field: str = 'vector')[source]¶ Zilliz vector store. You need to have pymilvus installed and a running Zilliz database. See the following documentation for how to run a Zilliz instance: https://docs.zilliz.com/docs/create-cluster IF USING L2/IP metric IT IS HIGHLY SUGGESTED TO NORMALIZE YOUR DATA. Parameters embedding_function (Embeddings) – Function used to embed the text. collection_name (str) – Which Zilliz collection to use. Defaults to “LangChainCollection”. connection_args (Optional[dict[str, any]]) – The connection args used for this class comes in the form of a dict. consistency_level (str) – The consistency level to use for a collection. Defaults to “Session”. index_params (Optional[dict]) – Which index params to use. Defaults to HNSW/AUTOINDEX depending on service. search_params (Optional[dict]) – Which search params to use. Defaults to default of index. drop_old (Optional[bool]) – Whether to drop the current collection. Defaults to False. The connection args used for this class comes in the form of a dict, here are a few of the options:
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-1
here are a few of the options: address (str): The actual address of Zillizinstance. Example address: “localhost:19530” uri (str): The uri of Zilliz instance. Example uri:“https://in03-ba4234asae.api.gcp-us-west1.zillizcloud.com”, host (str): The host of Zilliz instance. Default at “localhost”,PyMilvus will fill in the default host if only port is provided. port (str/int): The port of Zilliz instance. Default at 19530, PyMilvuswill fill in the default port if only host is provided. user (str): Use which user to connect to Zilliz instance. If user andpassword are provided, we will add related header in every RPC call. password (str): Required when user is provided. The passwordcorresponding to the user. token (str): API key, for serverless clusters which can be used asreplacements for user and password. secure (bool): Default is false. If set to true, tls will be enabled. client_key_path (str): If use tls two-way authentication, need to write the client.key path. client_pem_path (str): If use tls two-way authentication, need towrite the client.pem path. ca_pem_path (str): If use tls two-way authentication, need to writethe ca.pem path. server_pem_path (str): If use tls one-way authentication, need towrite the server.pem path. server_name (str): If use tls, need to write the common name. Example from langchain.vectorstores import Zilliz from langchain.embeddings import OpenAIEmbeddings embedding = OpenAIEmbeddings() # Connect to a Zilliz instance milvus_store = Milvus(
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-2
# Connect to a Zilliz instance milvus_store = Milvus( embedding_function = embedding, collection_name = “LangChainCollection”, connection_args = { “uri”: “https://in03-ba4234asae.api.gcp-us-west1.zillizcloud.com”, “user”: “temp”, “password”: “temp”, “token”: “temp”, # API key as replacements for user and password “secure”: True } drop_old: True, ) Raises ValueError – If the pymilvus python package is not installed. Initialize the Milvus vector store. Attributes embeddings Access the query embedding object if available. Methods __init__(embedding_function[, ...]) Initialize the Milvus 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, timeout, ...]) Insert text data into Milvus. 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.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-3
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_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_texts(texts, embedding[, metadatas, ...]) Create a Zilliz collection, indexes it with HNSW, and insert data. max_marginal_relevance_search(query[, k, ...]) Perform a search and return results that are reordered by MMR. max_marginal_relevance_search_by_vector(...) Perform a search and return results that are reordered by MMR. search(query, search_type, **kwargs) Return docs most similar to query using specified search type. similarity_search(query[, k, param, expr, ...]) Perform a similarity search against the query string. similarity_search_by_vector(embedding[, k, ...]) Perform a similarity search against the query string. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query[, k, ...]) Perform a search on a query string and return results with score. similarity_search_with_score_by_vector(embedding) Perform a search on a query string and return results with score.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-4
Perform a search on a query string and return results with score. __init__(embedding_function: Embeddings, collection_name: str = 'LangChainCollection', connection_args: Optional[dict[str, Any]] = None, consistency_level: str = 'Session', index_params: Optional[dict] = None, search_params: Optional[dict] = None, drop_old: Optional[bool] = False, *, primary_field: str = 'pk', text_field: str = 'text', vector_field: str = 'vector')¶ Initialize the Milvus vector store. 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, timeout: Optional[int] = None, batch_size: int = 1000, **kwargs: Any) → List[str]¶ Insert text data into Milvus. Inserting data when the collection has not be made yet will result in creating a new Collection. The data of the first entity decides
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-5
in creating a new Collection. The data of the first entity decides the schema of the new collection, the dim is extracted from the first embedding and the columns are decided by the first metadata dict. Metada keys will need to be present for all inserted values. At the moment there is no None equivalent in Milvus. Parameters texts (Iterable[str]) – The texts to embed, it is assumed that they all fit in memory. metadatas (Optional[List[dict]]) – Metadata dicts attached to each of the texts. Defaults to None. timeout (Optional[int]) – Timeout for each batch insert. Defaults to None. batch_size (int, optional) – Batch size to use for insertion. Defaults to 1000. Raises MilvusException – Failure to add texts Returns The resulting keys for each inserted element. 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¶ 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]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-6
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} ) # 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
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-7
) # 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¶ Return VectorStore initialized from documents and embeddings.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-8
Return VectorStore initialized from documents and embeddings. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, collection_name: str = 'LangChainCollection', connection_args: Optional[Dict[str, Any]] = None, consistency_level: str = 'Session', index_params: Optional[dict] = None, search_params: Optional[dict] = None, drop_old: bool = False, **kwargs: Any) → Zilliz[source]¶ Create a Zilliz collection, indexes it with HNSW, and insert data. Parameters texts (List[str]) – Text data. embedding (Embeddings) – Embedding function. metadatas (Optional[List[dict]]) – Metadata for each text if it exists. Defaults to None. collection_name (str, optional) – Collection name to use. Defaults to “LangChainCollection”. connection_args (dict[str, Any], optional) – Connection args to use. Defaults to DEFAULT_MILVUS_CONNECTION. consistency_level (str, optional) – Which consistency level to use. Defaults to “Session”. index_params (Optional[dict], optional) – Which index_params to use. Defaults to None. search_params (Optional[dict], optional) – Which search params to use. Defaults to None. drop_old (Optional[bool], optional) – Whether to drop the collection with that name if it exists. Defaults to False. Returns Zilliz Vector Store Return type Zilliz
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-9
Returns Zilliz Vector Store Return type Zilliz max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Document]¶ Perform a search and return results that are reordered by MMR. Parameters query (str) – The text being searched. k (int, optional) – How many results to give. Defaults to 4. fetch_k (int, optional) – Total results to select k from. 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 param (dict, optional) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document] max_marginal_relevance_search_by_vector(embedding: list[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Document]¶ Perform a search and return results that are reordered by MMR. Parameters embedding (str) – The embedding vector being searched.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-10
Parameters embedding (str) – The embedding vector being searched. k (int, optional) – How many results to give. Defaults to 4. fetch_k (int, optional) – Total results to select k from. 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 param (dict, optional) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document] 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, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Document]¶ Perform a similarity search against the query string. Parameters query (str) – The text to search. k (int, optional) – How many results to return. Defaults to 4. param (dict, optional) – The search params for the index type. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document]
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-11
Returns Document results for search. Return type List[Document] similarity_search_by_vector(embedding: List[float], k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Document]¶ Perform a similarity search against the query string. Parameters embedding (List[float]) – The embedding vector to search. k (int, optional) – How many results to return. Defaults to 4. param (dict, optional) – The search params for the index type. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document] 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, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Tuple[Document, float]]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-12
Perform a search on a query string and return results with score. For more information about the search parameters, take a look at the pymilvus documentation found here: https://milvus.io/api-reference/pymilvus/v2.2.6/Collection/search().md Parameters query (str) – The text being searched. k (int, optional) – The amount of results to return. Defaults to 4. param (dict) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Return type List[float], List[Tuple[Document, any, any]] similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Tuple[Document, float]]¶ Perform a search on a query string and return results with score. For more information about the search parameters, take a look at the pymilvus documentation found here: https://milvus.io/api-reference/pymilvus/v2.2.6/Collection/search().md Parameters embedding (List[float]) – The embedding vector being searched. k (int, optional) – The amount of results to return. Defaults to 4. param (dict) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
69df14cbb4a5-13
Defaults to None. kwargs – Collection.search() keyword arguments. Returns Result doc and score. Return type List[Tuple[Document, float]]
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.zilliz.Zilliz.html
53b3d39d5352-0
langchain.vectorstores.elasticsearch.ApproxRetrievalStrategy¶ class langchain.vectorstores.elasticsearch.ApproxRetrievalStrategy(query_model_id: Optional[str] = None, hybrid: Optional[bool] = False)[source]¶ Approximate retrieval strategy using the HNSW algorithm. Methods __init__([query_model_id, hybrid]) before_index_setup(client, text_field, ...) Executes before the index is created. index(dims_length, vector_query_field, ...) Create the mapping for the Elasticsearch index. query(query_vector, query, k, fetch_k, ...) Executes when a search is performed on the store. require_inference() Returns whether or not the strategy requires inference to be performed on the text before it is added to the index. __init__(query_model_id: Optional[str] = None, hybrid: Optional[bool] = False)[source]¶ before_index_setup(client: Elasticsearch, text_field: str, vector_query_field: str) → None¶ Executes before the index is created. Used for setting up any required Elasticsearch resources like a pipeline. Parameters client – The Elasticsearch client. text_field – The field containing the text data in the index. vector_query_field – The field containing the vector representations in the index. index(dims_length: Optional[int], vector_query_field: str, similarity: Optional[DistanceStrategy]) → Dict[source]¶ Create the mapping for the Elasticsearch index. query(query_vector: Optional[List[float]], query: Optional[str], k: int, fetch_k: int, vector_query_field: str, text_field: str, filter: List[dict], similarity: Optional[DistanceStrategy]) → Dict[source]¶ Executes when a search is performed on the store. Parameters query_vector – The query vector,
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elasticsearch.ApproxRetrievalStrategy.html
53b3d39d5352-1
Parameters query_vector – The query vector, or None if not using vector-based query. query – The text query, or None if not using text-based query. k – The total number of results to retrieve. fetch_k – The number of results to fetch initially. vector_query_field – The field containing the vector representations in the index. text_field – The field containing the text data in the index. filter – List of filter clauses to apply to the query. similarity – The similarity strategy to use, or None if not using one. Returns The Elasticsearch query body. Return type Dict require_inference() → bool¶ Returns whether or not the strategy requires inference to be performed on the text before it is added to the index. Returns Whether or not the strategy requires inference to be performed on the text before it is added to the index. Return type bool
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elasticsearch.ApproxRetrievalStrategy.html
95086f636593-0
langchain.vectorstores.qdrant.QdrantException¶ class langchain.vectorstores.qdrant.QdrantException[source]¶ Qdrant related exceptions.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.qdrant.QdrantException.html
ac2244dbdc41-0
langchain.vectorstores.milvus.Milvus¶ class langchain.vectorstores.milvus.Milvus(embedding_function: Embeddings, collection_name: str = 'LangChainCollection', connection_args: Optional[dict[str, Any]] = None, consistency_level: str = 'Session', index_params: Optional[dict] = None, search_params: Optional[dict] = None, drop_old: Optional[bool] = False, *, primary_field: str = 'pk', text_field: str = 'text', vector_field: str = 'vector')[source]¶ Milvus vector store. You need to install pymilvus and run Milvus. See the following documentation for how to run a Milvus instance: https://milvus.io/docs/install_standalone-docker.md If looking for a hosted Milvus, take a look at this documentation: https://zilliz.com/cloud and make use of the Zilliz vectorstore found in this project. IF USING L2/IP metric, IT IS HIGHLY SUGGESTED TO NORMALIZE YOUR DATA. Parameters embedding_function (Embeddings) – Function used to embed the text. collection_name (str) – Which Milvus collection to use. Defaults to “LangChainCollection”. connection_args (Optional[dict[str, any]]) – The connection args used for this class comes in the form of a dict. consistency_level (str) – The consistency level to use for a collection. Defaults to “Session”. index_params (Optional[dict]) – Which index params to use. Defaults to HNSW/AUTOINDEX depending on service. search_params (Optional[dict]) – Which search params to use. Defaults to default of index. drop_old (Optional[bool]) – Whether to drop the current collection. Defaults to False.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-1
to False. primary_field (str) – Name of the primary key field. Defaults to “pk”. text_field (str) – Name of the text field. Defaults to “text”. vector_field (str) – Name of the vector field. Defaults to “vector”. The connection args used for this class comes in the form of a dict, here are a few of the options: address (str): The actual address of Milvusinstance. Example address: “localhost:19530” uri (str): The uri of Milvus instance. Example uri:“http://randomwebsite:19530”, “tcp:foobarsite:19530”, “https://ok.s3.south.com:19530”. host (str): The host of Milvus instance. Default at “localhost”,PyMilvus will fill in the default host if only port is provided. port (str/int): The port of Milvus instance. Default at 19530, PyMilvuswill fill in the default port if only host is provided. user (str): Use which user to connect to Milvus instance. If user andpassword are provided, we will add related header in every RPC call. password (str): Required when user is provided. The passwordcorresponding to the user. secure (bool): Default is false. If set to true, tls will be enabled. client_key_path (str): If use tls two-way authentication, need to write the client.key path. client_pem_path (str): If use tls two-way authentication, need towrite the client.pem path. ca_pem_path (str): If use tls two-way authentication, need to writethe ca.pem path. server_pem_path (str): If use tls one-way authentication, need towrite the server.pem path.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-2
server_name (str): If use tls, need to write the common name. Example from langchain.vectorstores import Milvus from langchain.embeddings import OpenAIEmbeddings embedding = OpenAIEmbeddings() # Connect to a milvus instance on localhost milvus_store = Milvus( embedding_function = Embeddings, collection_name = “LangChainCollection”, drop_old = True, ) Raises ValueError – If the pymilvus python package is not installed. Initialize the Milvus vector store. Attributes embeddings Access the query embedding object if available. Methods __init__(embedding_function[, ...]) Initialize the Milvus 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, timeout, ...]) Insert text data into Milvus. 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.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-3
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_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_texts(texts, embedding[, metadatas, ...]) Create a Milvus collection, indexes it with HNSW, and insert data. max_marginal_relevance_search(query[, k, ...]) Perform a search and return results that are reordered by MMR. max_marginal_relevance_search_by_vector(...) Perform a search and return results that are reordered by MMR. search(query, search_type, **kwargs) Return docs most similar to query using specified search type. similarity_search(query[, k, param, expr, ...]) Perform a similarity search against the query string. similarity_search_by_vector(embedding[, k, ...]) Perform a similarity search against the query string. similarity_search_with_relevance_scores(query) Return docs and relevance scores in the range [0, 1]. similarity_search_with_score(query[, k, ...]) Perform a search on a query string and return results with score. similarity_search_with_score_by_vector(embedding) Perform a search on a query string and return results with score.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-4
Perform a search on a query string and return results with score. __init__(embedding_function: Embeddings, collection_name: str = 'LangChainCollection', connection_args: Optional[dict[str, Any]] = None, consistency_level: str = 'Session', index_params: Optional[dict] = None, search_params: Optional[dict] = None, drop_old: Optional[bool] = False, *, primary_field: str = 'pk', text_field: str = 'text', vector_field: str = 'vector')[source]¶ Initialize the Milvus vector store. 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, timeout: Optional[int] = None, batch_size: int = 1000, **kwargs: Any) → List[str][source]¶ Insert text data into Milvus. Inserting data when the collection has not be made yet will result in creating a new Collection. The data of the first entity decides
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-5
in creating a new Collection. The data of the first entity decides the schema of the new collection, the dim is extracted from the first embedding and the columns are decided by the first metadata dict. Metada keys will need to be present for all inserted values. At the moment there is no None equivalent in Milvus. Parameters texts (Iterable[str]) – The texts to embed, it is assumed that they all fit in memory. metadatas (Optional[List[dict]]) – Metadata dicts attached to each of the texts. Defaults to None. timeout (Optional[int]) – Timeout for each batch insert. Defaults to None. batch_size (int, optional) – Batch size to use for insertion. Defaults to 1000. Raises MilvusException – Failure to add texts Returns The resulting keys for each inserted element. 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¶ 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]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-6
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} ) # 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
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-7
) # 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¶ Return VectorStore initialized from documents and embeddings.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-8
Return VectorStore initialized from documents and embeddings. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, collection_name: str = 'LangChainCollection', connection_args: dict[str, Any] = {'host': 'localhost', 'password': '', 'port': '19530', 'secure': False, 'user': ''}, consistency_level: str = 'Session', index_params: Optional[dict] = None, search_params: Optional[dict] = None, drop_old: bool = False, **kwargs: Any) → Milvus[source]¶ Create a Milvus collection, indexes it with HNSW, and insert data. Parameters texts (List[str]) – Text data. embedding (Embeddings) – Embedding function. metadatas (Optional[List[dict]]) – Metadata for each text if it exists. Defaults to None. collection_name (str, optional) – Collection name to use. Defaults to “LangChainCollection”. connection_args (dict[str, Any], optional) – Connection args to use. Defaults to DEFAULT_MILVUS_CONNECTION. consistency_level (str, optional) – Which consistency level to use. Defaults to “Session”. index_params (Optional[dict], optional) – Which index_params to use. Defaults to None. search_params (Optional[dict], optional) – Which search params to use. Defaults to None. drop_old (Optional[bool], optional) – Whether to drop the collection with that name if it exists. Defaults to False. Returns Milvus Vector Store Return type Milvus
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-9
Returns Milvus Vector Store Return type Milvus max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Document][source]¶ Perform a search and return results that are reordered by MMR. Parameters query (str) – The text being searched. k (int, optional) – How many results to give. Defaults to 4. fetch_k (int, optional) – Total results to select k from. 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 param (dict, optional) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document] max_marginal_relevance_search_by_vector(embedding: list[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Document][source]¶ Perform a search and return results that are reordered by MMR. Parameters embedding (str) – The embedding vector being searched.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-10
Parameters embedding (str) – The embedding vector being searched. k (int, optional) – How many results to give. Defaults to 4. fetch_k (int, optional) – Total results to select k from. 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 param (dict, optional) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document] 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, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Document][source]¶ Perform a similarity search against the query string. Parameters query (str) – The text to search. k (int, optional) – How many results to return. Defaults to 4. param (dict, optional) – The search params for the index type. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document]
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-11
Returns Document results for search. Return type List[Document] similarity_search_by_vector(embedding: List[float], k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Document][source]¶ Perform a similarity search against the query string. Parameters embedding (List[float]) – The embedding vector to search. k (int, optional) – How many results to return. Defaults to 4. param (dict, optional) – The search params for the index type. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document] 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, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-12
Perform a search on a query string and return results with score. For more information about the search parameters, take a look at the pymilvus documentation found here: https://milvus.io/api-reference/pymilvus/v2.2.6/Collection/search().md Parameters query (str) – The text being searched. k (int, optional) – The amount of results to return. Defaults to 4. param (dict) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Return type List[float], List[Tuple[Document, any, any]] similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶ Perform a search on a query string and return results with score. For more information about the search parameters, take a look at the pymilvus documentation found here: https://milvus.io/api-reference/pymilvus/v2.2.6/Collection/search().md Parameters embedding (List[float]) – The embedding vector being searched. k (int, optional) – The amount of results to return. Defaults to 4. param (dict) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
ac2244dbdc41-13
Defaults to None. kwargs – Collection.search() keyword arguments. Returns Result doc and score. Return type List[Tuple[Document, float]] Examples using Milvus¶ Milvus Zilliz
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.milvus.Milvus.html
0738b1b6b35e-0
langchain.vectorstores.redis.schema.RedisField¶ class langchain.vectorstores.redis.schema.RedisField[source]¶ Bases: BaseModel 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 name: str [Required]¶ 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 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¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.redis.schema.RedisField.html
0738b1b6b35e-1
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. classmethod from_orm(obj: Any) → Model¶ 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¶ 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.redis.schema.RedisField.html
ddd8fa3ed40c-0
langchain.vectorstores.docarray.in_memory.DocArrayInMemorySearch¶ class langchain.vectorstores.docarray.in_memory.DocArrayInMemorySearch(doc_index: BaseDocIndex, embedding: Embeddings)[source]¶ In-memory DocArray storage for exact search. To use it, you should have the docarray package with version >=0.32.0 installed. You can install it with pip install “langchain[docarray]”. Initialize a vector store from DocArray’s DocIndex. Attributes doc_cls embeddings Access the query embedding object if available. Methods __init__(doc_index, embedding) Initialize a vector store from DocArray's DocIndex. 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]) Embed texts and add to the vector store. 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])
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.docarray.in_memory.DocArrayInMemorySearch.html
ddd8fa3ed40c-1
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_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_params(embedding[, metric]) Initialize DocArrayInMemorySearch store. from_texts(texts, embedding[, metadatas]) Create an DocArrayInMemorySearch store and insert data. 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__(doc_index: BaseDocIndex, embedding: Embeddings)¶ Initialize a vector store from DocArray’s DocIndex. 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.docarray.in_memory.DocArrayInMemorySearch.html
ddd8fa3ed40c-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, **kwargs: Any) → List[str]¶ Embed texts and add to the vector store. 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.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.docarray.in_memory.DocArrayInMemorySearch.html
ddd8fa3ed40c-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.docarray.in_memory.DocArrayInMemorySearch.html
ddd8fa3ed40c-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.docarray.in_memory.DocArrayInMemorySearch.html
ddd8fa3ed40c-5
Return VectorStore initialized from documents and embeddings. classmethod from_params(embedding: Embeddings, metric: Literal['cosine_sim', 'euclidian_dist', 'sgeuclidean_dist'] = 'cosine_sim', **kwargs: Any) → DocArrayInMemorySearch[source]¶ Initialize DocArrayInMemorySearch store. Parameters embedding (Embeddings) – Embedding function. metric (str) – metric for exact nearest-neighbor search. Can be one of: “cosine_sim”, “euclidean_dist” and “sqeuclidean_dist”. Defaults to “cosine_sim”. **kwargs – Other keyword arguments to be passed to the get_doc_cls method. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[Dict[Any, Any]]] = None, **kwargs: Any) → DocArrayInMemorySearch[source]¶ Create an DocArrayInMemorySearch store and insert data. Parameters texts (List[str]) – Text data. embedding (Embeddings) – Embedding function. metadatas (Optional[List[Dict[Any, Any]]]) – Metadata for each text if it exists. Defaults to None. metric (str) – metric for exact nearest-neighbor search. Can be one of: “cosine_sim”, “euclidean_dist” and “sqeuclidean_dist”. Defaults to “cosine_sim”. Returns DocArrayInMemorySearch Vector Store 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.docarray.in_memory.DocArrayInMemorySearch.html
ddd8fa3ed40c-6
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, **kwargs: Any) → List[Document]¶ 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.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.docarray.in_memory.DocArrayInMemorySearch.html
ddd8fa3ed40c-7
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. **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]]¶ 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 text and cosine distance in float for each. Lower score represents more similarity. Examples using DocArrayInMemorySearch¶ DocArray InMemorySearch
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.docarray.in_memory.DocArrayInMemorySearch.html
a4e606b2fafb-0
langchain.vectorstores.dashvector.DashVector¶ class langchain.vectorstores.dashvector.DashVector(collection: Any, embedding: Embeddings, text_field: str)[source]¶ DashVector vector store. To use, you should have the dashvector python package installed. Example from langchain.vectorstores import dashvector from langchain.embeddings.openai import OpenAIEmbeddings import dashvector client = dashvector.Client.init(api_key="***") client.create("langchain") collection = client.get("langchain") embeddings = OpenAIEmbeddings() vectorstore = Dashvector(collection, embeddings.embed_query, "text") Initialize with DashVector collection. Attributes embeddings Access the query embedding object if available. Methods __init__(collection, embedding, text_field) Initialize with DashVector collection. 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, batch_size]) 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.dashvector.DashVector.html
a4e606b2fafb-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. delete([ids]) Delete by vector ID. from_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_texts(texts, embedding[, metadatas, ...]) Return DashVector VectorStore initialized from texts and embeddings. 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]) 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 most similar to query text , alone with relevance scores. similarity_search_with_score(*args, **kwargs) Run similarity search with distance. __init__(collection: Any, embedding: Embeddings, text_field: str)[source]¶ Initialize with DashVector collection. async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.dashvector.DashVector.html
a4e606b2fafb-2
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, ids: Optional[List[str]] = None, batch_size: int = 25, **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 ids associated with the texts. batch_size – Optional batch size to upsert docs. 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.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.dashvector.DashVector.html
a4e606b2fafb-3
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.dashvector.DashVector.html
a4e606b2fafb-4
) # 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) → bool[source]¶ Delete by vector ID. Parameters ids – List of ids to delete. Returns True if deletion is successful, False otherwise.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.dashvector.DashVector.html
a4e606b2fafb-5
Returns True if deletion is successful, False otherwise. 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, dashvector_api_key: Optional[str] = None, collection_name: str = 'langchain', text_field: str = 'text', batch_size: int = 25, ids: Optional[List[str]] = None, **kwargs: Any) → DashVector[source]¶ Return DashVector VectorStore initialized from texts and embeddings. This is the quick way to get started with dashvector vector store. Example from langchain.vectorstores import DashVector from langchain.embeddings import OpenAIEmbeddings import dashvector embeddings = OpenAIEmbeddings() dashvector = DashVector.from_documents( docs, embeddings, dashvector_api_key=”{DASHVECTOR_API_KEY}” ) max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, 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 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.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.dashvector.DashVector.html
a4e606b2fafb-6
to maximum diversity and 1 to minimum diversity. Defaults to 0.5. filter – Doc fields filter conditions that meet the SQL where clause specification. 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] = 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. filter – Doc fields filter conditions that meet the SQL where clause specification. 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[str] = None, **kwargs: Any) → List[Document][source]¶ Return docs most similar to query. Parameters query – Text to search documents similar to. k – Number of documents to return. Default to 4. filter – Doc fields filter conditions that meet the SQL where clause specification. Returns List of Documents most similar to the query text.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.dashvector.DashVector.html
a4e606b2fafb-7
specification. Returns List of Documents most similar to the query text. similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[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. filter – Doc fields filter conditions that meet the SQL where clause specification. Returns List of Documents most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, filter: Optional[str] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶ Return docs most similar to query text , alone with relevance scores. Less is more similar, more is more dissimilar. Parameters query – input text k – Number of Documents to return. Defaults to 4. filter – Doc fields filter conditions that meet the SQL where clause specification. 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 DashVector¶ DashVector
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.dashvector.DashVector.html
c686eecb3ad1-0
langchain.vectorstores.redis.schema.HNSWVectorField¶ class langchain.vectorstores.redis.schema.HNSWVectorField[source]¶ Bases: RedisVectorField 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 algorithm: Literal['HNSW'] = 'HNSW'¶ param datatype: str = 'FLOAT32'¶ param dims: int [Required]¶ param distance_metric: langchain.vectorstores.redis.schema.RedisDistanceMetric = 'COSINE'¶ param ef_construction: int = 200¶ param ef_runtime: int = 10¶ param epsilon: float = 0.8¶ param initial_cap: int = 20000¶ param m: int = 16¶ param name: str [Required]¶ as_field() → VectorField[source]¶ 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
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.redis.schema.HNSWVectorField.html
c686eecb3ad1-1
the new model: you should trust this data 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¶ 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¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.redis.schema.HNSWVectorField.html
c686eecb3ad1-2
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¶ 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.redis.schema.HNSWVectorField.html
894f4b257e06-0
langchain.vectorstores.elasticsearch.SparseRetrievalStrategy¶ class langchain.vectorstores.elasticsearch.SparseRetrievalStrategy(model_id: Optional[str] = None)[source]¶ Sparse retrieval strategy using the text_expansion processor. Methods __init__([model_id]) before_index_setup(client, text_field, ...) Executes before the index is created. index(dims_length, vector_query_field, ...) Executes when the index is created. query(query_vector, query, k, fetch_k, ...) Executes when a search is performed on the store. require_inference() Returns whether or not the strategy requires inference to be performed on the text before it is added to the index. __init__(model_id: Optional[str] = None)[source]¶ before_index_setup(client: Elasticsearch, text_field: str, vector_query_field: str) → None[source]¶ Executes before the index is created. Used for setting up any required Elasticsearch resources like a pipeline. Parameters client – The Elasticsearch client. text_field – The field containing the text data in the index. vector_query_field – The field containing the vector representations in the index. index(dims_length: Optional[int], vector_query_field: str, similarity: Optional[DistanceStrategy]) → Dict[source]¶ Executes when the index is created. Parameters dims_length – Numeric length of the embedding vectors, or None if not using vector-based query. vector_query_field – The field containing the vector representations in the index. similarity – The similarity strategy to use, or None if not using one. Returns The Elasticsearch settings and mappings for the strategy. Return type Dict
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elasticsearch.SparseRetrievalStrategy.html
894f4b257e06-1
Returns The Elasticsearch settings and mappings for the strategy. Return type Dict query(query_vector: Optional[List[float]], query: Optional[str], k: int, fetch_k: int, vector_query_field: str, text_field: str, filter: List[dict], similarity: Optional[DistanceStrategy]) → Dict[source]¶ Executes when a search is performed on the store. Parameters query_vector – The query vector, or None if not using vector-based query. query – The text query, or None if not using text-based query. k – The total number of results to retrieve. fetch_k – The number of results to fetch initially. vector_query_field – The field containing the vector representations in the index. text_field – The field containing the text data in the index. filter – List of filter clauses to apply to the query. similarity – The similarity strategy to use, or None if not using one. Returns The Elasticsearch query body. Return type Dict require_inference() → bool[source]¶ Returns whether or not the strategy requires inference to be performed on the text before it is added to the index. Returns Whether or not the strategy requires inference to be performed on the text before it is added to the index. Return type bool
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.elasticsearch.SparseRetrievalStrategy.html
66e383f1c3b8-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
da345d1b411f-0
langchain.vectorstores.sklearn.SKLearnVectorStoreException¶ class langchain.vectorstores.sklearn.SKLearnVectorStoreException[source]¶ Exception raised by SKLearnVectorStore.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.sklearn.SKLearnVectorStoreException.html
d7f28365ce2a-0
langchain.vectorstores.singlestoredb.SingleStoreDB¶ class langchain.vectorstores.singlestoredb.SingleStoreDB(embedding: Embeddings, *, distance_strategy: DistanceStrategy = DistanceStrategy.DOT_PRODUCT, table_name: str = 'embeddings', content_field: str = 'content', metadata_field: str = 'metadata', vector_field: str = 'vector', pool_size: int = 5, max_overflow: int = 10, timeout: float = 30, **kwargs: Any)[source]¶ SingleStore DB vector store. The prerequisite for using this class is the installation of the singlestoredb Python package. The SingleStoreDB vectorstore can be created by providing an embedding function and the relevant parameters for the database connection, connection pool, and optionally, the names of the table and the fields to use. Initialize with necessary components. Parameters embedding (Embeddings) – A text embedding model. distance_strategy (DistanceStrategy, optional) – Determines the strategy employed for calculating the distance between vectors in the embedding space. Defaults to DOT_PRODUCT. Available options are: - DOT_PRODUCT: Computes the scalar product of two vectors. This is the default behavior EUCLIDEAN_DISTANCE: Computes the Euclidean distance betweentwo vectors. This metric considers the geometric distance in the vector space, and might be more suitable for embeddings that rely on spatial relationships. table_name (str, optional) – Specifies the name of the table in use. Defaults to “embeddings”. content_field (str, optional) – Specifies the field to store the content. Defaults to “content”. metadata_field (str, optional) – Specifies the field to store metadata. Defaults to “metadata”. vector_field (str, optional) – Specifies the field to store the vector. Defaults to “vector”.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-1
Defaults to “vector”. pool (Following arguments pertain to the connection) – pool_size (int, optional) – Determines the number of active connections in the pool. Defaults to 5. max_overflow (int, optional) – Determines the maximum number of connections allowed beyond the pool_size. Defaults to 10. timeout (float, optional) – Specifies the maximum wait time in seconds for establishing a connection. Defaults to 30. connection (database) – host (str, optional) – Specifies the hostname, IP address, or URL for the database connection. The default scheme is “mysql”. user (str, optional) – Database username. password (str, optional) – Database password. port (int, optional) – Database port. Defaults to 3306 for non-HTTP connections, 80 for HTTP connections, and 443 for HTTPS connections. database (str, optional) – Database name. the (Additional optional arguments provide further customization over) – connection – pure_python (bool, optional) – Toggles the connector mode. If True, operates in pure Python mode. local_infile (bool, optional) – Allows local file uploads. charset (str, optional) – Specifies the character set for string values. ssl_key (str, optional) – Specifies the path of the file containing the SSL key. ssl_cert (str, optional) – Specifies the path of the file containing the SSL certificate. ssl_ca (str, optional) – Specifies the path of the file containing the SSL certificate authority. ssl_cipher (str, optional) – Sets the SSL cipher list. ssl_disabled (bool, optional) – Disables SSL usage. ssl_verify_cert (bool, optional) – Verifies the server’s certificate. Automatically enabled if ssl_ca is specified.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-2
Automatically enabled if ssl_ca is specified. ssl_verify_identity (bool, optional) – Verifies the server’s identity. conv (dict[int, Callable], optional) – A dictionary of data conversion functions. credential_type (str, optional) – Specifies the type of authentication to use: auth.PASSWORD, auth.JWT, or auth.BROWSER_SSO. autocommit (bool, optional) – Enables autocommits. results_type (str, optional) – Determines the structure of the query results: tuples, namedtuples, dicts. results_format (str, optional) – Deprecated. This option has been renamed to results_type. Examples Basic Usage: from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import SingleStoreDB vectorstore = SingleStoreDB( OpenAIEmbeddings(), host="https://user:[email protected]:3306/database" ) Advanced Usage: from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import SingleStoreDB vectorstore = SingleStoreDB( OpenAIEmbeddings(), distance_strategy=DistanceStrategy.EUCLIDEAN_DISTANCE, host="127.0.0.1", port=3306, user="user", password="password", database="db", table_name="my_custom_table", pool_size=10, timeout=60, ) Using environment variables: from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import SingleStoreDB os.environ['SINGLESTOREDB_URL'] = 'me:[email protected]/my_db' vectorstore = SingleStoreDB(OpenAIEmbeddings()) Attributes embeddings Access the query embedding object if available.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-3
Attributes embeddings Access the query embedding object if available. vector_field Pass the rest of the kwargs to the connection. connection_kwargs Add program name and version to connection attributes. Methods __init__(embedding, *[, distance_strategy, ...]) 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, embeddings]) Add more texts 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_documents(documents, embedding, **kwargs)
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-4
from_documents(documents, embedding, **kwargs) Return VectorStore initialized from documents and embeddings. from_texts(texts, embedding[, metadatas, ...]) Create a SingleStoreDB vectorstore from raw documents. This is a user-friendly interface that: 1. Embeds documents. 2. Creates a new table for the embeddings in SingleStoreDB. 3. Adds the documents to the newly created table. This is intended to be a quick way to get started. .. rubric:: Example. 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]) Returns the most similar indexed documents to the query text. 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]) Return docs most similar to query. __init__(embedding: Embeddings, *, distance_strategy: DistanceStrategy = DistanceStrategy.DOT_PRODUCT, table_name: str = 'embeddings', content_field: str = 'content', metadata_field: str = 'metadata', vector_field: str = 'vector', pool_size: int = 5, max_overflow: int = 10, timeout: float = 30, **kwargs: Any)[source]¶ Initialize with necessary components. Parameters embedding (Embeddings) – A text embedding model. distance_strategy (DistanceStrategy, optional) – Determines the strategy employed for calculating
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-5
distance_strategy (DistanceStrategy, optional) – Determines the strategy employed for calculating the distance between vectors in the embedding space. Defaults to DOT_PRODUCT. Available options are: - DOT_PRODUCT: Computes the scalar product of two vectors. This is the default behavior EUCLIDEAN_DISTANCE: Computes the Euclidean distance betweentwo vectors. This metric considers the geometric distance in the vector space, and might be more suitable for embeddings that rely on spatial relationships. table_name (str, optional) – Specifies the name of the table in use. Defaults to “embeddings”. content_field (str, optional) – Specifies the field to store the content. Defaults to “content”. metadata_field (str, optional) – Specifies the field to store metadata. Defaults to “metadata”. vector_field (str, optional) – Specifies the field to store the vector. Defaults to “vector”. pool (Following arguments pertain to the connection) – pool_size (int, optional) – Determines the number of active connections in the pool. Defaults to 5. max_overflow (int, optional) – Determines the maximum number of connections allowed beyond the pool_size. Defaults to 10. timeout (float, optional) – Specifies the maximum wait time in seconds for establishing a connection. Defaults to 30. connection (database) – host (str, optional) – Specifies the hostname, IP address, or URL for the database connection. The default scheme is “mysql”. user (str, optional) – Database username. password (str, optional) – Database password. port (int, optional) – Database port. Defaults to 3306 for non-HTTP connections, 80 for HTTP connections, and 443 for HTTPS connections. database (str, optional) – Database name.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-6
database (str, optional) – Database name. the (Additional optional arguments provide further customization over) – connection – pure_python (bool, optional) – Toggles the connector mode. If True, operates in pure Python mode. local_infile (bool, optional) – Allows local file uploads. charset (str, optional) – Specifies the character set for string values. ssl_key (str, optional) – Specifies the path of the file containing the SSL key. ssl_cert (str, optional) – Specifies the path of the file containing the SSL certificate. ssl_ca (str, optional) – Specifies the path of the file containing the SSL certificate authority. ssl_cipher (str, optional) – Sets the SSL cipher list. ssl_disabled (bool, optional) – Disables SSL usage. ssl_verify_cert (bool, optional) – Verifies the server’s certificate. Automatically enabled if ssl_ca is specified. ssl_verify_identity (bool, optional) – Verifies the server’s identity. conv (dict[int, Callable], optional) – A dictionary of data conversion functions. credential_type (str, optional) – Specifies the type of authentication to use: auth.PASSWORD, auth.JWT, or auth.BROWSER_SSO. autocommit (bool, optional) – Enables autocommits. results_type (str, optional) – Determines the structure of the query results: tuples, namedtuples, dicts. results_format (str, optional) – Deprecated. This option has been renamed to results_type. Examples Basic Usage: from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import SingleStoreDB vectorstore = SingleStoreDB( OpenAIEmbeddings(), host="https://user:[email protected]:3306/database"
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-7
) Advanced Usage: from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import SingleStoreDB vectorstore = SingleStoreDB( OpenAIEmbeddings(), distance_strategy=DistanceStrategy.EUCLIDEAN_DISTANCE, host="127.0.0.1", port=3306, user="user", password="password", database="db", table_name="my_custom_table", pool_size=10, timeout=60, ) Using environment variables: from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import SingleStoreDB os.environ['SINGLESTOREDB_URL'] = 'me:[email protected]/my_db' vectorstore = SingleStoreDB(OpenAIEmbeddings()) 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.singlestoredb.SingleStoreDB.html
d7f28365ce2a-8
Returns List of IDs of the added texts. Return type List[str] add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, embeddings: Optional[List[List[float]]] = None, **kwargs: Any) → List[str][source]¶ Add more texts to the vectorstore. Parameters texts (Iterable[str]) – Iterable of strings/text to add to the vectorstore. metadatas (Optional[List[dict]], optional) – Optional list of metadatas. Defaults to None. embeddings (Optional[List[List[float]]], optional) – Optional pre-generated embeddings. Defaults to None. Returns empty list 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¶ 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) → SingleStoreDBRetriever[source]¶ Return VectorStoreRetriever initialized from this VectorStore. Parameters
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-9
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}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever(
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-10
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¶ Return VectorStore initialized from documents and embeddings.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-11
Return VectorStore initialized from documents and embeddings. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, distance_strategy: DistanceStrategy = DistanceStrategy.DOT_PRODUCT, table_name: str = 'embeddings', content_field: str = 'content', metadata_field: str = 'metadata', vector_field: str = 'vector', pool_size: int = 5, max_overflow: int = 10, timeout: float = 30, **kwargs: Any) → SingleStoreDB[source]¶ Create a SingleStoreDB vectorstore from raw documents. This is a user-friendly interface that: Embeds documents. Creates a new table for the embeddings in SingleStoreDB. Adds the documents to the newly created table. This is intended to be a quick way to get started. .. rubric:: Example 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.
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-12
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]¶ Returns the most similar indexed documents to the query text. Uses cosine similarity. Parameters query (str) – The query text for which to find similar documents. k (int) – The number of documents to return. Default is 4. filter (dict) – A dictionary of metadata fields and values to filter by. Returns A list of documents that are most similar to the query text. Return type List[Document] Examples similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html
d7f28365ce2a-13
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]¶ Return docs most similar to query. Uses cosine similarity. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter – A dictionary of metadata fields and values to filter by. Defaults to None. Returns List of Documents most similar to the query and score for each Examples using SingleStoreDB¶ SingleStoreDB
https://api.python.langchain.com/en/latest/vectorstores/langchain.vectorstores.singlestoredb.SingleStoreDB.html