Tony20100/langchain_full huggingface dataset:
embedding (Embeddings) – Embedding function to use.
kwargs (Any) – 
Return type
VST
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.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
Parameters
query (str) – Text 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]
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.
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
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]
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
kwargs (Any) – 
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
)
# 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.
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]
async asimilarity_search(query: str, k: int = 4, **kwargs: Any) → List[Document]¶
Return docs most similar to query.
Parameters
query (str) – Input text.
k (int) – Number of Documents to return. Defaults to 4.
kwargs (Any) – 
Returns
List of Documents most similar to the query.
Return type
List[Document]
async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶
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.
kwargs (Any) – 
Returns
kwargs (Any) – 
Returns
List of Documents most similar to the query vector.
Return type
List[Document]
async asimilarity_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.
**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]]
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, delete_all: Optional[bool] = None, namespace: Optional[str] = None, filter: Optional[dict] = None, **kwargs: Any) → None¶
Delete by vector IDs or filter.
:param ids: List of ids to delete.
:param filter: Dictionary of conditions to filter vectors to delete.
Parameters
ids (Optional[List[str]]) – 
delete_all (Optional[bool]) – 
namespace (Optional[str]) – 
filter (Optional[dict]) – 
kwargs (Any) – 
Return type
None
kwargs (Any) – 
Return type
None
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_existing_index(index_name: str, embedding: Embeddings, text_key: str = 'text', namespace: Optional[str] = None, pool_threads: int = 4) → PineconeVectorStore¶
Load pinecone vectorstore from index name.
Parameters
index_name (str) – 
embedding (Embeddings) – 
text_key (str) – 
namespace (Optional[str]) – 
pool_threads (int) – 
Return type
PineconeVectorStore
classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, batch_size: int = 32, text_key: str = 'text', namespace: Optional[str] = None, index_name: Optional[str] = None, upsert_kwargs: Optional[dict] = None, pool_threads: int = 4, embeddings_chunk_size: int = 1000, **kwargs: Any) → PineconeVectorStore¶
Construct Pinecone wrapper from raw documents.
This is a user friendly interface that:
Embeds documents.
Adds the documents to a provided Pinecone index
This is intended to be a quick way to get started.
The pool_threads affects the speed of the upsert operations.
Setup: set the PINECONE_API_KEY environment variable to your Pinecone API key.
Example
Example
from langchain_pinecone import PineconeVectorStore
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
index_name = "my-index"
vectorstore = PineconeVectorStore.from_texts(
    texts,
    index_name=index_name,
    embedding=embedding,
    namespace=namespace,
)
Parameters
texts (List[str]) – 
embedding (Embeddings) – 
metadatas (Optional[List[dict]]) – 
ids (Optional[List[str]]) – 
batch_size (int) – 
text_key (str) – 
namespace (Optional[str]) – 
index_name (Optional[str]) – 
upsert_kwargs (Optional[dict]) – 
pool_threads (int) – 
embeddings_chunk_size (int) – 
kwargs (Any) – 
Return type
PineconeVectorStore
classmethod get_pinecone_index(index_name: Optional[str], pool_threads: int = 4, *, pinecone_api_key: Optional[str] = None) → Index¶
Return a Pinecone Index instance.
Parameters
index_name (Optional[str]) – Name of the index to use.
pool_threads (int) – Number of threads to use for index upsert.
pinecone_api_key (Optional[str]) – 
Returns
Pinecone Index instance.
Return type
Index
max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[dict] = None, namespace: Optional[str] = None, **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
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
Parameters
query (str) – Text 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]) – 
namespace (Optional[str]) – 
kwargs (Any) – 
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, namespace: Optional[str] = None, **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.
filter (Optional[dict]) – 
namespace (Optional[str]) – 
kwargs (Any) – 
Returns
List of Documents selected by maximal marginal relevance.
Return type
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, filter: Optional[dict] = None, namespace: Optional[str] = None, **kwargs: Any) → List[Document]¶
Return pinecone documents 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]) – Dictionary of argument(s) to filter on metadata
namespace (Optional[str]) – Namespace to search in. Default will search in ‘’ namespace.
kwargs (Any) – 
Returns
List of Documents most similar to the query and score for each
Return type
List[Document]
similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[Document]¶
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.
kwargs (Any) – 
Returns
List of Documents most similar to the query vector.
Return type
List[Document]
List of Documents most similar to the query vector.
Return type
List[Document]
similarity_search_by_vector_with_score(embedding: List[float], *, k: int = 4, filter: Optional[dict] = None, namespace: Optional[str] = None) → List[Tuple[Document, float]]¶
Return pinecone documents most similar to embedding, along with scores.
Parameters
embedding (List[float]) – 
k (int) – 
filter (Optional[dict]) – 
namespace (Optional[str]) – 
Return type
List[Tuple[Document, float]]
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.
**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, namespace: Optional[str] = None) → List[Tuple[Document, float]]¶
Return pinecone documents most similar to query, along with scores.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filter (Optional[dict]) – Dictionary of argument(s) to filter on metadata
langchain_community.vectorstores.infinispanvs.Infinispan¶
class langchain_community.vectorstores.infinispanvs.Infinispan(**kwargs: Any)[source]¶
Helper class for Infinispan REST interface.
This class exposes the Infinispan operations needed to
create and set up a vector db.
You need a running Infinispan (15+) server without authentication.
You can easily start one, see:
https://github.com/rigazilla/infinispan-vector#run-infinispan
Methods
__init__(**kwargs)
cache_clear(cache_name)
Clear a cache :param cache_name: name of the cache.
cache_delete(name)
Delete a cache :param name: name of the cache.
cache_exists(cache_name)
Check if a cache exists :param cache_name: name of the cache.
cache_post(name, config)
Create a cache :param name: name of the cache.
get(key, cache_name)
Get an entry :param key: key of the entry :type key: str :param cache_name: target cache :type cache_name: str
index_clear(cache_name)
Clear an index on a cache :param cache_name: name of the cache.
index_reindex(cache_name)
Rebuild index on a cache :param cache_name: name of the cache.
post(key, data, cache_name)
Post an entry :param key: key of the entry :type key: str :param data: content of the entry in json format :type data: str :param cache_name: target cache :type cache_name: str
put(key, data, cache_name)
put(key, data, cache_name)
Put an entry :param key: key of the entry :type key: str :param data: content of the entry in json format :type data: str :param cache_name: target cache :type cache_name: str
req_query(query, cache_name[, local])
Request a query :param query: query requested :type query: str :param cache_name: name of the target cache :type cache_name: str :param local: whether the query is local to clustered :type local: boolean
resource_exists(api_url)
Check if a resource exists :param api_url: url of the resource.
schema_delete(name)
Delete a schema :param name: name of the schema.
schema_post(name, proto)
Deploy a schema :param name: name of the schema.
Parameters
kwargs (Any) – 
__init__(**kwargs: Any)[source]¶
Parameters
kwargs (Any) – 
cache_clear(cache_name: str) → Response[source]¶
Clear a cache
:param cache_name: name of the cache.
:type cache_name: str
Returns
An http Response containing the result of the operation
Parameters
cache_name (str) – 
Return type
Response
cache_delete(name: str) → Response[source]¶
Delete a cache
:param name: name of the cache.
:type name: str
Returns
An http Response containing the result of the operation
Parameters
name (str) – 
Return type
Response
cache_exists(cache_name: str) → bool[source]¶
Check if a cache exists
:param cache_name: name of the cache.
:type cache_name: str
Returns
True if cache exists
Parameters
cache_name (str) – 
Return type
bool
cache_post(name: str, config: str) → Response[source]¶
Create a cache
cache_post(name: str, config: str) → Response[source]¶
Create a cache
:param name: name of the cache.
:type name: str
:param config: configuration of the cache.
:type config: str
Returns
An http Response containing the result of the operation
Parameters
name (str) – 
config (str) – 
Return type
Response
get(key: str, cache_name: str) → Response[source]¶
Get an entry
:param key: key of the entry
:type key: str
:param cache_name: target cache
:type cache_name: str
Returns
An http Response containing the entry or errors
Parameters
key (str) – 
cache_name (str) – 
Return type
Response
index_clear(cache_name: str) → Response[source]¶
Clear an index on a cache
:param cache_name: name of the cache.
:type cache_name: str
Returns
An http Response containing the result of the operation
Parameters
cache_name (str) – 
Return type
Response
index_reindex(cache_name: str) → Response[source]¶
Rebuild index on a cache
:param cache_name: name of the cache.
:type cache_name: str
Returns
An http Response containing the result of the operation
Parameters
cache_name (str) – 
Return type
Response
post(key: str, data: str, cache_name: str) → Response[source]¶
Post an entry
:param key: key of the entry
:type key: str
:param data: content of the entry in json format
:type data: str
:param cache_name: target cache
:type cache_name: str
Returns
An http Response containing the result of the operation
Parameters
key (str) – 
data (str) – 
cache_name (str) – 
Return type
Response
data (str) – 
cache_name (str) – 
Return type
Response
put(key: str, data: str, cache_name: str) → Response[source]¶
Put an entry
:param key: key of the entry
:type key: str
:param data: content of the entry in json format
:type data: str
:param cache_name: target cache
:type cache_name: str
Returns
An http Response containing the result of the operation
Parameters
key (str) – 
data (str) – 
cache_name (str) – 
Return type
Response
req_query(query: str, cache_name: str, local: bool = False) → Response[source]¶
Request a query
:param query: query requested
:type query: str
:param cache_name: name of the target cache
:type cache_name: str
:param local: whether the query is local to clustered
:type local: boolean
Returns
An http Response containing the result set or errors
Parameters
query (str) – 
cache_name (str) – 
local (bool) – 
Return type
Response
static resource_exists(api_url: str) → bool[source]¶
Check if a resource exists
:param api_url: url of the resource.
:type api_url: str
Returns
true if resource exists
Parameters
api_url (str) – 
Return type
bool
schema_delete(name: str) → Response[source]¶
Delete a schema
:param name: name of the schema.
:type name: str
Returns
An http Response containing the result of the operation
Parameters
name (str) – 
Return type
Response
schema_post(name: str, proto: str) → Response[source]¶
Deploy a schema
:param name: name of the schema. Will be used as a key
:type name: str
:param proto: protobuf schema
langchain_community.vectorstores.zilliz.Zilliz¶
class langchain_community.vectorstores.zilliz.Zilliz(embedding_function: Embeddings, collection_name: str = 'LangChainCollection', collection_description: str = '', collection_properties: Optional[dict[str, Any]] = None, 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, auto_id: bool = False, *, primary_field: str = 'pk', text_field: str = 'text', vector_field: str = 'vector', metadata_field: Optional[str] = None, partition_key_field: Optional[str] = None, partition_names: Optional[list] = None, replica_number: int = 1, timeout: Optional[float] = None, num_shards: Optional[int] = None)[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.
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.
auto_id (bool) – Whether to enable auto id for primary key. Defaults to False.
If False, you needs to provide text ids (string less than 65535 bytes).
If True, Milvus will generate unique integers as primary keys.
collection_description (str) – 
collection_properties (Optional[dict[str, Any]]) – 
primary_field (str) – 
text_field (str) – 
vector_field (str) – 
metadata_field (Optional[str]) – 
partition_key_field (Optional[str]) – 
partition_names (Optional[list]) – 
replica_number (int) – 
timeout (Optional[float]) – 
num_shards (Optional[int]) – 
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 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_community.vectorstores import Zilliz
from langchain_community.embeddings import OpenAIEmbeddings
embedding = OpenAIEmbeddings()
# 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.
Parameters
embedding_function (Embeddings) – 
collection_name (str) – 
collection_description (str) – 
collection_properties (Optional[dict[str, Any]]) – 
connection_args (Optional[dict[str, Any]]) – 
consistency_level (str) –