Tony20100/langchain_full huggingface dataset:
es_user – Username to use when connecting to Elasticsearch.
es_password – Password to use when connecting to Elasticsearch.
es_api_key – API key to use when connecting to Elasticsearch.
es_connection – Optional pre-existing Elasticsearch connection.
vector_query_field – Optional. Name of the field
to store the embedding vectors in.
query_field – Optional. Name of the field to store the texts in.
bulk_kwargs (Optional[Dict]) – Optional. Additional arguments to pass to
Elasticsearch bulk.
documents (List[Document]) – 
kwargs (Any) – 
Return type
ElasticsearchStore
classmethod from_texts(texts: List[str], embedding: Optional[Embeddings] = None, metadatas: Optional[List[Dict[str, Any]]] = None, bulk_kwargs: Optional[Dict] = None, **kwargs: Any) → ElasticsearchStore[source]¶
Construct ElasticsearchStore wrapper from raw documents.
Example
from langchain_elasticsearch.vectorstores import ElasticsearchStore
from langchain_openai import OpenAIEmbeddings
db = ElasticsearchStore.from_texts(
    texts,
    // embeddings optional if using
    // a strategy that doesn't require inference
    embeddings,
    index_name="langchain-demo",
    es_url="http://localhost:9200"
)
Parameters
texts (List[str]) – List of texts to add to the Elasticsearch index.
embedding (Optional[Embeddings]) – Embedding function to use to embed the texts.
metadatas (Optional[List[Dict[str, Any]]]) – Optional list of metadatas associated with the texts.
index_name – Name of the Elasticsearch index to create.
es_url – URL of the Elasticsearch instance to connect to.
cloud_id – Cloud ID of the Elasticsearch instance to connect to.
es_user – Username to use when connecting to Elasticsearch.
es_user – Username to use when connecting to Elasticsearch.
es_password – Password to use when connecting to Elasticsearch.
es_api_key – API key to use when connecting to Elasticsearch.
es_connection – Optional pre-existing Elasticsearch connection.
vector_query_field – Optional. Name of the field to
store the embedding vectors in.
query_field – Optional. Name of the field to store the texts in.
distance_strategy – Optional. Name of the distance
strategy to use. Defaults to “COSINE”.
can be one of “COSINE”,
“EUCLIDEAN_DISTANCE”, “DOT_PRODUCT”,
“MAX_INNER_PRODUCT”.
bulk_kwargs (Optional[Dict]) – Optional. Additional arguments to pass to
Elasticsearch bulk.
kwargs (Any) – 
Return type
ElasticsearchStore
max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, fields: Optional[List[str]] = None, *, custom_query: Optional[Callable[[Dict[str, Any], Optional[str]], Dict[str, Any]]] = None, doc_builder: Optional[Callable[[Dict], Document]] = None, **kwargs: Any) → List[Document][source]¶
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversityamong 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.
to maximum diversity and 1 to minimum diversity.
Defaults to 0.5.
fields (Optional[List[str]]) – Other fields to get from elasticsearch source. These fields
will be added to the document metadata.
custom_query (Optional[Callable[[Dict[str, Any], Optional[str]], Dict[str, Any]]]) – 
doc_builder (Optional[Callable[[Dict], Document]]) – 
kwargs (Any) – 
Returns
A 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, **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]
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”.
“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, fetch_k: int = 50, filter: Optional[List[dict]] = None, *, custom_query: Optional[Callable[[Dict[str, Any], Optional[str]], Dict[str, Any]]] = None, doc_builder: Optional[Callable[[Dict], Document]] = None, **kwargs: Any) → List[Document][source]¶
Return Elasticsearch 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.
fetch_k (int) – Number of Documents to fetch to pass to knn num_candidates.
filter (Optional[List[dict]]) – Array of Elasticsearch filter clauses to apply to the query.
custom_query (Optional[Callable[[Dict[str, Any], Optional[str]], Dict[str, Any]]]) – 
doc_builder (Optional[Callable[[Dict], Document]]) – 
kwargs (Any) – 
Returns
List of Documents most similar to the query,
in descending order of similarity.
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_relevance_scores(embedding: List[float], k: int = 4, filter: Optional[List[Dict]] = None, *, custom_query: Optional[Callable[[Dict[str, Any], Optional[str]], Dict[str, Any]]] = None, doc_builder: Optional[Callable[[Dict], Document]] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
Return Elasticsearch documents most similar to query, along with scores.
Parameters
embedding (List[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filter (Optional[List[Dict]]) – Array of Elasticsearch filter clauses to apply to the query.
custom_query (Optional[Callable[[Dict[str, Any], Optional[str]], Dict[str, Any]]]) – 
doc_builder (Optional[Callable[[Dict], Document]]) – 
kwargs (Any) – 
Returns
List of Documents most similar to the embedding and score for each
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
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[List[dict]] = None, *, custom_query: Optional[Callable[[Dict[str, Any], Optional[str]], Dict[str, Any]]] = None, doc_builder: Optional[Callable[[Dict], Document]] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
Return Elasticsearch 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[List[dict]]) – Array of Elasticsearch filter clauses to apply to the query.
custom_query (Optional[Callable[[Dict[str, Any], Optional[str]], Dict[str, Any]]]) – 
doc_builder (Optional[Callable[[Dict], Document]]) – 
kwargs (Any) – 
Returns
List of Documents most similar to the query and score for each
Return type
List[Tuple[Document, float]]
langchain_community.vectorstores.elasticsearch.ExactRetrievalStrategy¶
class langchain_community.vectorstores.elasticsearch.ExactRetrievalStrategy(*args, **kwargs)[source]¶
[Deprecated] Exact retrieval strategy using the script_score query.
Notes
Deprecated since version 0.0.27: Use Use class in langchain-elasticsearch package instead.
Methods
__init__(*args, **kwargs)
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__(*args: Any, **kwargs: Any) → Any¶
Parameters
self (Any) – 
args (Any) – 
kwargs (Any) – 
Return type
Any
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 (Elasticsearch) – The Elasticsearch client.
text_field (str) – The field containing the text data in the index.
vector_query_field (str) – The field containing the vector
representations in the index.
Return type
None
index(dims_length: Optional[int], vector_query_field: str, similarity: Optional[DistanceStrategy]) → Dict[source]¶
Create the mapping for the Elasticsearch index.
Parameters
dims_length (Optional[int]) – 
vector_query_field (str) – 
similarity (Optional[DistanceStrategy]) – 
Return type
similarity (Optional[DistanceStrategy]) – 
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: Optional[List[dict]], similarity: Optional[DistanceStrategy]) → Dict[source]¶
Executes when a search is performed on the store.
Parameters
query_vector (Optional[List[float]]) – The query vector,
or None if not using vector-based query.
query (Optional[str]) – The text query, or None if not using text-based query.
k (int) – The total number of results to retrieve.
fetch_k (int) – The number of results to fetch initially.
vector_query_field (str) – The field containing the vector
representations in the index.
text_field (str) – The field containing the text data in the index.
filter (Optional[List[dict]]) – List of filter clauses to apply to the query.
similarity (Optional[DistanceStrategy]) – 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
langchain_community.vectorstores.vikingdb.VikingDB¶
class langchain_community.vectorstores.vikingdb.VikingDB(embedding_function: Embeddings, collection_name: str = 'LangChainCollection', connection_args: Optional[VikingDBConfig] = None, index_params: Optional[dict] = None, drop_old: Optional[bool] = False, **kwargs: Any)[source]¶
vikingdb as a vector store
In order to use this you need to have a database instance.
See the following documentation for details:
https://www.volcengine.com/docs/6459/1167774
Attributes
embeddings
Access the query embedding object if available.
Methods
__init__(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_texts(texts[, metadatas, batch_size])
Insert text data into VikingDB.
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.
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)
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[, ...])
Create a collection, indexes it 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[, params])
Perform a similarity search against the query string.
similarity_search_by_vector(embedding[, params])
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[, params])
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.
Parameters
embedding_function (Embeddings) – 
collection_name (str) – 
connection_args (Optional[VikingDBConfig]) –
collection_name (str) – 
connection_args (Optional[VikingDBConfig]) – 
index_params (Optional[dict]) – 
drop_old (Optional[bool]) – 
kwargs (Any) – 
__init__(embedding_function: Embeddings, collection_name: str = 'LangChainCollection', connection_args: Optional[VikingDBConfig] = None, index_params: Optional[dict] = None, drop_old: Optional[bool] = False, **kwargs: Any)[source]¶
Parameters
embedding_function (Embeddings) – 
collection_name (str) – 
connection_args (Optional[VikingDBConfig]) – 
index_params (Optional[dict]) – 
drop_old (Optional[bool]) – 
kwargs (Any) – 
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.
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: List[str], metadatas: Optional[List[dict]] = None, batch_size: int = 1000, **kwargs: Any) → List[str][source]¶
Insert text data into VikingDB.
Parameters
texts (List[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
documents (List[Document]) – List of Documents to add to the vectorstore.
embedding (Embeddings) – Embedding function to use.
kwargs (Any) – 
Return type
VST
async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → VST¶
Return VectorStore initialized from texts and embeddings.
Parameters
texts (List[str]) – Texts to add to the vectorstore.
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]
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, **kwargs: Any) → None[source]¶
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]
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, connection_args: Optional[VikingDBConfig] = None, metadatas: Optional[List[dict]] = None, collection_name: str = 'LangChainCollection', index_params: Optional[dict] = None, drop_old: bool = False, **kwargs: Any)[source]¶
Create a collection, indexes it and insert data.
Parameters
texts (List[str]) – 
embedding (Embeddings) – 
connection_args (Optional[VikingDBConfig]) – 
metadatas (Optional[List[dict]]) – 
collection_name (str) – 
index_params (Optional[dict]) – 
drop_old (bool) – 
kwargs (Any) – 
max_marginal_relevance_search(query: str, k: int = 4, lambda_mult: float = 0.5, params: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶
Perform a search and return results that are reordered by MMR.
Parameters
query (str) – 
k (int) – 
lambda_mult (float) – 
params (Optional[dict]) – 
kwargs (Any) – 
Return type
List[Document]
kwargs (Any) – 
Return type
List[Document]
max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, lambda_mult: float = 0.5, params: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶
Perform a search and return results that are reordered by MMR.
Parameters
embedding (List[float]) – 
k (int) – 
lambda_mult (float) – 
params (Optional[dict]) – 
kwargs (Any) – 
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, params: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶
Perform a similarity search against the query string.
Parameters
query (str) – 
params (Optional[dict]) – 
kwargs (Any) – 
Return type
List[Document]
similarity_search_by_vector(embedding: List[float], params: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶
Perform a similarity search against the query string.
Parameters
embedding (List[float]) – 
params (Optional[dict]) – 
kwargs (Any) – 
Return type
List[Document]
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
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, params: Optional[dict] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
Perform a search on a query string and return results with score.
Parameters
query (str) – 
params (Optional[dict]) – 
kwargs (Any) – 
Return type
List[Tuple[Document, float]]
similarity_search_with_score_by_vector(embedding: List[float], params: Optional[dict] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
Perform a search on a query string and return results with score.
Parameters
embedding (List[float]) – 
params (Optional[dict]) – 
kwargs (Any) – 
Return type
List[Tuple[Document, float]]
Examples using VikingDB¶
viking DB