Tony20100/langchain_full huggingface dataset:
Return type
List[Tuple[Document, float]]
async asimilarity_search_with_score(*args: Any, **kwargs: Any) → List[Tuple[Document, float]]¶
Run similarity search with distance.
Returns
List of Tuples of (doc, similarity_score)
Parameters
args (Any) – 
kwargs (Any) – 
Return type
List[Tuple[Document, float]]
delete(ids: Optional[List[str]] = None, filter: Optional[dict] = None) → Optional[bool][source]¶
Delete entries by filter with metadata values
Parameters
ids (Optional[List[str]]) – Deletion with ids is not supported! A ValueError will be raised.
filter (Optional[dict]) – A dictionary of metadata fields and values to filter by.
An empty filter ({}) will delete all entries in the table.
Returns
True, if deletion is technically successful.
Deletion of zero entries, due to non-matching filters is a success.
Return type
Optional[bool]
classmethod from_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶
Return VectorStore initialized from documents and embeddings.
Parameters
documents (List[Document]) – List of Documents to add to the vectorstore.
embedding (Embeddings) – Embedding function to use.
kwargs (Any) – 
Return type
VST
kwargs (Any) – 
Return type
VST
classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, connection: dbapi.Connection = None, distance_strategy: DistanceStrategy = DistanceStrategy.COSINE, table_name: str = 'EMBEDDINGS', content_column: str = 'VEC_TEXT', metadata_column: str = 'VEC_META', vector_column: str = 'VEC_VECTOR', vector_column_length: int = -1, *, specific_metadata_columns: Optional[List[str]] = None)[source]¶
Create a HanaDB instance from raw documents.
This is a user-friendly interface that:
Embeds documents.
Creates a table if it does not yet exist.
Adds the documents to the table.
This is intended to be a quick way to get started.
Parameters
texts (List[str]) – 
embedding (Embeddings) – 
metadatas (Optional[List[dict]]) – 
connection (dbapi.Connection) – 
distance_strategy (DistanceStrategy) – 
table_name (str) – 
content_column (str) – 
metadata_column (str) – 
vector_column (str) – 
vector_column_length (int) – 
specific_metadata_columns (Optional[List[str]]) – 
max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[dict] = None) → 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 (str) – search query text.
k (int) – Number of Documents to return. Defaults to 4.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.
lambda_mult (float) – 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 (Optional[dict]) – Filter on metadata properties, e.g.
{
”str_property”: “foo”,
“int_property”: 123
}
Returns
List of Documents selected by maximal marginal relevance.
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, filter: Optional[dict] = None) → 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 (List[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.
lambda_mult (float) – 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 (Optional[dict]) – 
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[Document]
search(query: str, search_type: str, **kwargs: Any) → List[Document]¶
Return docs most similar to query using specified search type.
Parameters
query (str) – Input text
Parameters
query (str) – Input text
search_type (str) – Type of search to perform. Can be “similarity”,
“mmr”, or “similarity_score_threshold”.
**kwargs (Any) – Arguments to pass to the search method.
Return type
List[Document]
similarity_search(query: str, k: int = 4, filter: Optional[dict] = None) → List[Document][source]¶
Return docs most similar to query.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filter (Optional[dict]) – A dictionary of metadata fields and values to filter by.
Defaults to None.
Returns
List of Documents most similar to the query
Return type
List[Document]
similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None) → List[Document][source]¶
Return docs most similar to embedding vector.
Parameters
embedding (List[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filter (Optional[dict]) – A dictionary of metadata fields and values to filter by.
Defaults to None.
Returns
List of Documents most similar to the query vector.
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 (str) – Input text.
k (int) – Number of Documents to return. Defaults to 4.
k (int) – Number of Documents to return. Defaults to 4.
**kwargs (Any) – 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)
Return type
List[Tuple[Document, float]]
similarity_search_with_score(query: str, k: int = 4, filter: Optional[dict] = None) → List[Tuple[Document, float]][source]¶
Return documents and score values most similar to query.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filter (Optional[dict]) – A dictionary of metadata fields and values to filter by.
Defaults to None.
Returns
List of tuples (containing a Document and a score) that are
most similar to the query
Return type
List[Tuple[Document, float]]
similarity_search_with_score_and_vector_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None) → List[Tuple[Document, float, List[float]]][source]¶
Return docs most similar to the given embedding.
Parameters
query – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filter (Optional[dict]) – A dictionary of metadata fields and values to filter by.
Defaults to None.
embedding (List[float]) – 
Returns
List of Documents most similar to the query and
score and the document’s embedding vector for each
Return type
List[Tuple[Document, float, List[float]]]
Return type
List[Tuple[Document, float, List[float]]]
similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None) → List[Tuple[Document, float]][source]¶
Return docs most similar to the given embedding.
Parameters
query – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filter (Optional[dict]) – A dictionary of metadata fields and values to filter by.
Defaults to None.
embedding (List[float]) – 
Returns
List of Documents most similar to the query and score for each
Return type
List[Tuple[Document, float]]
Examples using HanaDB¶
SAP HANA Cloud Vector Engine
langchain_community.vectorstores.baiduvectordb.BaiduVectorDB¶
class langchain_community.vectorstores.baiduvectordb.BaiduVectorDB(embedding: ~langchain_core.embeddings.embeddings.Embeddings, connection_params: ~langchain_community.vectorstores.baiduvectordb.ConnectionParams, table_params: ~langchain_community.vectorstores.baiduvectordb.TableParams = <langchain_community.vectorstores.baiduvectordb.TableParams object>, database_name: str = 'LangChainDatabase', table_name: str = 'LangChainTable', drop_old: ~typing.Optional[bool] = False)[source]¶
Baidu VectorDB as a vector store.
In order to use this you need to have a database instance.
See the following documentation for details:
https://cloud.baidu.com/doc/VDB/index.html
Attributes
embeddings
Access the query embedding object if available.
field_id
field_metadata
field_text
field_vector
index_vector
Methods
__init__(embedding, connection_params[, ...])
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, batch_size])
Insert text data into Baidu VectorDB.
adelete([ids])
Delete by vector ID or other criteria.
afrom_documents(documents, embedding, **kwargs)
Return VectorStore initialized from documents and embeddings.
afrom_texts(texts, embedding[, metadatas])
Return VectorStore initialized from texts and embeddings.
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 and relevance scores in the range [0, 1].
asimilarity_search_with_score(*args, **kwargs)
Run similarity search with distance.
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 table, 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(...)
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, 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)
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.
Parameters
embedding (Embeddings) – 
connection_params (ConnectionParams) – 
table_params (TableParams) – 
database_name (str) – 
table_name (str) – 
drop_old (Optional[bool]) – 
__init__(embedding: ~langchain_core.embeddings.embeddings.Embeddings, connection_params: ~langchain_community.vectorstores.baiduvectordb.ConnectionParams, table_params: ~langchain_community.vectorstores.baiduvectordb.TableParams = <langchain_community.vectorstores.baiduvectordb.TableParams object>, database_name: str = 'LangChainDatabase', table_name: str = 'LangChainTable', drop_old: ~typing.Optional[bool] = False)[source]¶
Parameters
embedding (Embeddings) – 
connection_params (ConnectionParams) – 
table_params (TableParams) – 
database_name (str) – 
table_name (str) – 
drop_old (Optional[bool]) – 
async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶
Run more documents through the embeddings and add to the vectorstore.
Parameters
documents (List[Document]) – Documents to add to the vectorstore.
kwargs (Any) – 
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.
Parameters
texts (Iterable[str]) – Iterable of strings to add to the vectorstore.
metadatas (Optional[List[dict]]) – Optional list of metadatas associated with the texts.
**kwargs (Any) – vectorstore specific parameters.
Returns
List of ids from adding the texts into the vectorstore.
Return type
List[str]
add_documents(documents: List[Document], **kwargs: Any) → List[str]¶
Run more documents through the embeddings and add to the vectorstore.
Parameters
documents (List[Document]) – Documents to add to the vectorstore.
kwargs (Any) – 
Returns
List of IDs of the added texts.
Return type
List[str]
add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, batch_size: int = 1000, **kwargs: Any) → List[str][source]¶
Insert text data into Baidu VectorDB.
Parameters
texts (Iterable[str]) – 
metadatas (Optional[List[dict]]) – 
batch_size (int) – 
kwargs (Any) – 
Return type
List[str]
async adelete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool]¶
Delete by vector ID or other criteria.
Parameters
ids (Optional[List[str]]) – List of ids to delete.
**kwargs (Any) – Other keyword arguments that subclasses might use.
Returns
True if deletion is successful,
False otherwise, None if not implemented.
Return type
Optional[bool]
async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) → VST¶
Return VectorStore initialized from documents and embeddings.
Parameters
Run similarity search with distance.
Returns
List of Tuples of (doc, similarity_score)
Parameters
args (Any) – 
kwargs (Any) – 
Return type
List[Tuple[Document, float]]
delete(ids: Optional[List[str]] = None, **kwargs: Any) → Optional[bool]¶
Delete by vector ID or other criteria.
Parameters
ids (Optional[List[str]]) – List of ids to delete.
**kwargs (Any) – 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.
Parameters
documents (List[Document]) – List of Documents to add to the vectorstore.
embedding (Embeddings) – Embedding function to use.
kwargs (Any) – 
Return type
VST
classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, connection_params: Optional[ConnectionParams] = None, table_params: Optional[TableParams] = None, database_name: str = 'LangChainDatabase', table_name: str = 'LangChainTable', drop_old: Optional[bool] = False, **kwargs: Any) → BaiduVectorDB[source]¶
Create a table, indexes it with HNSW, and insert data.
Parameters
texts (List[str]) – 
embedding (Embeddings) – 
metadatas (Optional[List[dict]]) – 
connection_params (Optional[ConnectionParams]) – 
table_params (Optional[TableParams]) – 
database_name (str) – 
table_name (str) –
database_name (str) – 
table_name (str) – 
drop_old (Optional[bool]) – 
kwargs (Any) – 
Return type
BaiduVectorDB
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, **kwargs: Any) → List[Document][source]¶
Perform a search and return results that are reordered by MMR.
Parameters
query (str) – 
k (int) – 
fetch_k (int) – 
lambda_mult (float) – 
param (Optional[dict]) – 
expr (Optional[str]) – 
kwargs (Any) – 
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, **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 (List[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.
lambda_mult (float) – 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.
kwargs (Any) – 
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[Document]
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[Document]
search(query: str, search_type: str, **kwargs: Any) → List[Document]¶
Return docs most similar to query using specified search type.
Parameters
query (str) – Input text
search_type (str) – Type of search to perform. Can be “similarity”,
“mmr”, or “similarity_score_threshold”.
**kwargs (Any) – Arguments to pass to the search method.
Return type
List[Document]
similarity_search(query: str, k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, **kwargs: Any) → List[Document][source]¶
Perform a similarity search against the query string.
Parameters
query (str) – 
k (int) – 
param (Optional[dict]) – 
expr (Optional[str]) – 
kwargs (Any) – 
Return type
List[Document]
similarity_search_by_vector(embedding: List[float], k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, **kwargs: Any) → List[Document][source]¶
Perform a similarity search against the query string.
Parameters
embedding (List[float]) – 
k (int) – 
param (Optional[dict]) – 
expr (Optional[str]) – 
kwargs (Any) – 
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
0 is dissimilar, 1 is most similar.
Parameters
query (str) – Input text.
k (int) – Number of Documents to return. Defaults to 4.
**kwargs (Any) – 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)
Return type
List[Tuple[Document, float]]
similarity_search_with_score(query: str, k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
Perform a search on a query string and return results with score.
Parameters
query (str) – 
k (int) – 
param (Optional[dict]) – 
expr (Optional[str]) – 
kwargs (Any) – 
Return type
List[Tuple[Document, float]]
Examples using BaiduVectorDB¶
Baidu
Baidu VectorDB
langchain_community.vectorstores.neo4j_vector.dict_to_yaml_str¶
langchain_community.vectorstores.neo4j_vector.dict_to_yaml_str(input_dict: Dict, indent: int = 0) → str[source]¶
Convert a dictionary to a YAML-like string without using external libraries.
Parameters:
- input_dict (dict): The dictionary to convert.
- indent (int): The current indentation level.
Returns:
- str: The YAML-like string representation of the input dictionary.
Parameters
input_dict (Dict) – 
indent (int) – 
Return type
str
langchain_community.vectorstores.deeplake.DeepLake¶
class langchain_community.vectorstores.deeplake.DeepLake(dataset_path: str = './deeplake/', token: Optional[str] = None, embedding: Optional[Embeddings] = None, embedding_function: Optional[Embeddings] = None, read_only: bool = False, ingestion_batch_size: int = 1024, num_workers: int = 0, verbose: bool = True, exec_option: Optional[str] = None, runtime: Optional[Dict] = None, index_params: Optional[Dict[str, Union[int, str]]] = None, **kwargs: Any)[source]¶
Activeloop Deep Lake vector store.
We integrated deeplake’s similarity search and filtering for fast prototyping.
Now, it supports Tensor Query Language (TQL) for production use cases
over billion rows.
Why Deep Lake?
Not only stores embeddings, but also the original data with version control.
Serverless, doesn’t require another service and can be used with majorcloud providers (S3, GCS, etc.)
More than just a multi-modal vector store. You can use the datasetto fine-tune your own LLM models.
To use, you should have the deeplake python package installed.
Example
from langchain_community.vectorstores import DeepLake
from langchain_community.embeddings.openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
vectorstore = DeepLake("langchain_store", embeddings.embed_query)
Creates an empty DeepLakeVectorStore or loads an existing one.
The DeepLakeVectorStore is located at the specified path.
Examples
>>> # Create a vector store with default tensors
>>> deeplake_vectorstore = DeepLake(
...        path = <path_for_storing_Data>,
... )
>>>
...        path = <path_for_storing_Data>,
... )
>>>
>>> # Create a vector store in the Deep Lake Managed Tensor Database
>>> data = DeepLake(
...        path = "hub://org_id/dataset_name",
...        runtime = {"tensor_db": True},
... )
Parameters
dataset_path (str) – The full path for storing to the Deep Lake
Vector Store. It can be:
- a Deep Lake cloud path of the form hub://org_id/dataset_name.
Requires registration with Deep Lake.
an s3 path of the form s3://bucketname/path/to/dataset.Credentials are required in either the environment or passed to
the creds argument.
a local file system path of the form ./path/to/datasetor ~/path/to/dataset or path/to/dataset.
a memory path of the form mem://path/to/dataset which doesn’tsave the dataset but keeps it in memory instead.
Should be used only for testing as it does not persist.
Defaults to _LANGCHAIN_DEFAULT_DEEPLAKE_PATH.
token (str, optional) – Activeloop token, for fetching credentials
to the dataset at path if it is a Deep Lake dataset.
Tokens are normally autogenerated. Optional.
embedding (Embeddings, optional) – Function to convert
either documents or query. Optional.
embedding_function (Embeddings, optional) – Function to convert
either documents or query. Optional. Deprecated: keeping this
parameter for backwards compatibility.
read_only (bool) – Open dataset in read-only mode. Default is False.
ingestion_batch_size (int) – During data ingestion, data is divided
into batches. Batch size is the size of each batch.
Default is 1024.
num_workers (int) – Number of workers to use during data ingestion.
Default is 0.
Default is 0.
verbose (bool) – Print dataset summary after each operation.
Default is True.
exec_option (str, optional) – Default method for search execution.
It could be either "auto", "python", "compute_engine"
or "tensor_db". Defaults to "auto".
If None, it’s set to “auto”.
- auto- Selects the best execution method based on the storage
location of the Vector Store. It is the default option.
python - Pure-python implementation that runs on the client andcan be used for data stored anywhere. WARNING: using this option
with big datasets is discouraged because it can lead to
memory issues.
compute_engine - Performant C++ implementation of the Deep LakeCompute Engine that runs on the client and can be used for any data
stored in or connected to Deep Lake. It cannot be used with
in-memory or local datasets.
tensor_db - Performant and fully-hosted Managed Tensor Databasethat is responsible for storage and query execution. Only available
for data stored in the Deep Lake Managed Database. Store datasets
in this database by specifying runtime = {“tensor_db”: True}
during dataset creation.
runtime (Dict, optional) – Parameters for creating the Vector Store in
Deep Lake’s Managed Tensor Database. Not applicable when loading an
existing Vector Store. To create a Vector Store in the Managed Tensor
Database, set runtime = {“tensor_db”: True}.
index_params (Optional[Dict[str, Union[int, str]]], optional) – Dictionary
containing information about vector index that will be created. Defaults
to None, which will utilize DEFAULT_VECTORSTORE_INDEX_PARAMS from
deeplake.constants. The specified key-values override the default
ones.
- threshold: The threshold for the dataset size above which an index
will be created for the embedding tensor. When the threshold value