Tony20100/langchain_full huggingface dataset:
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.
create_knn_index(mapping)
Create a new k-NN index in Elasticsearch.
delete([ids])
Delete by vector ID or other criteria.
from_documents(documents, embedding, **kwargs)
Return VectorStore initialized from documents and embeddings.
from_texts(texts, embedding[, metadatas])
Create a new ElasticKnnSearch instance and add a list of texts to the
knn_hybrid_search([query, k, query_vector, ...])
Perform a hybrid k-NN and text search on the Elasticsearch index.
knn_search([query, k, query_vector, ...])
Perform a k-NN search on the Elasticsearch index.
max_marginal_relevance_search(query[, k, ...])
Return docs selected using the maximal marginal relevance.
max_marginal_relevance_search_by_vector(...)
Return docs selected using the maximal marginal relevance.
search(query, search_type, **kwargs)
search(query, search_type, **kwargs)
Return docs most similar to query using specified search type.
similarity_search(query[, k, filter])
Pass through to knn_search
similarity_search_by_vector(embedding[, k])
Return docs most similar to embedding vector.
similarity_search_with_relevance_scores(query)
Return docs and relevance scores in the range [0, 1].
similarity_search_with_score(query[, k])
Pass through to knn_search including score
__init__(index_name: str, embedding: Embeddings, es_connection: Optional['Elasticsearch'] = None, es_cloud_id: Optional[str] = None, es_user: Optional[str] = None, es_password: Optional[str] = None, vector_query_field: Optional[str] = 'vector', query_field: Optional[str] = 'text')[source]¶
Parameters
index_name (str) – 
embedding (Embeddings) – 
es_connection (Optional['Elasticsearch']) – 
es_cloud_id (Optional[str]) – 
es_user (Optional[str]) – 
es_password (Optional[str]) – 
vector_query_field (Optional[str]) – 
query_field (Optional[str]) – 
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
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[Any, Any]]] = None, model_id: Optional[str] = None, refresh_indices: bool = False, **kwargs: Any) → List[str][source]¶
Add a list of texts to the Elasticsearch index.
Parameters
texts (Iterable[str]) – The texts to add to the index.
metadatas (List[Dict[Any, Any]], optional) – A list of metadata dictionaries
to associate with the texts.
model_id (str, optional) – The ID of the model to use for transforming the
texts into vectors.
refresh_indices (bool, optional) – Whether to refresh the Elasticsearch
indices after adding the texts.
**kwargs – Arbitrary keyword arguments.
Returns
A list of IDs for the added texts.
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.
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]]
create_knn_index(mapping: Dict) → None[source]¶
Create a new k-NN index in Elasticsearch.
Parameters
mapping (Dict) – The mapping to use for the new index.
Returns
None
Return type
None
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[Any, Any]]] = None, **kwargs: Any) → ElasticKnnSearch[source]¶
Create a new ElasticKnnSearch instance and add a list of texts to theElasticsearch index.
Parameters
texts (List[str]) – The texts to add to the index.
embedding (Embeddings) – The embedding model to use for transforming the
texts into vectors.
metadatas (List[Dict[Any, Any]], optional) – A list of metadata dictionaries
to associate with the texts.
**kwargs – Arbitrary keyword arguments.
Returns
A new ElasticKnnSearch instance.
Return type
ElasticKnnSearch
knn_hybrid_search(query: Optional[str] = None, k: Optional[int] = 10, query_vector: Optional[List[float]] = None, model_id: Optional[str] = None, size: Optional[int] = 10, source: Optional[bool] = True, knn_boost: Optional[float] = 0.9, query_boost: Optional[float] = 0.1, fields: Optional[Union[List[Mapping[str, Any]], Tuple[Mapping[str, Any], ...]]] = None, page_content: Optional[str] = 'text') → List[Tuple[Document, float]][source]¶
Perform a hybrid k-NN and text search on the Elasticsearch index.
Parameters
query (str, optional) – The query text to search for.
k (int, optional) – The number of nearest neighbors to return.
query_vector (List[float], optional) – The query vector to search for.
model_id (str, optional) – The ID of the model to use for transforming the
query text into a vector.
size (int, optional) – The number of search results to return.
source (bool, optional) – Whether to return the source of the search results.
knn_boost (float, optional) – The boost value to apply to the k-NN search
results.
results.
query_boost (float, optional) – The boost value to apply to the text search
results.
fields (List[Mapping[str, Any]], optional) – The fields to return in the
search results.
page_content (str, optional) – The name of the field that contains the page
content.
Returns
A list of tuples, where each tuple contains a Document object and a score.
Return type
List[Tuple[Document, float]]
knn_search(query: Optional[str] = None, k: Optional[int] = 10, query_vector: Optional[List[float]] = None, model_id: Optional[str] = None, size: Optional[int] = 10, source: Optional[bool] = True, fields: Optional[Union[List[Mapping[str, Any]], Tuple[Mapping[str, Any], ...]]] = None, page_content: Optional[str] = 'text') → List[Tuple[Document, float]][source]¶
Perform a k-NN search on the Elasticsearch index.
Parameters
query (str, optional) – The query text to search for.
k (int, optional) – The number of nearest neighbors to return.
query_vector (List[float], optional) – The query vector to search for.
model_id (str, optional) – The ID of the model to use for transforming the
query text into a vector.
size (int, optional) – The number of search results to return.
source (bool, optional) – Whether to return the source of the search results.
fields (List[Mapping[str, Any]], optional) – The fields to return in the
search results.
page_content (str, optional) – The name of the field that contains the page
content.
Returns
A list of tuples, where each tuple contains a Document object and a score.
Return type
A list of tuples, where each tuple contains a Document object and a score.
Return type
List[Tuple[Document, float]]
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 (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]
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
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”.
**kwargs (Any) – Arguments to pass to the search method.
Return type
List[Document]
similarity_search(query: str, k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶
Pass through to knn_search
Parameters
query (str) – 
k (int) – 
filter (Optional[dict]) – 
kwargs (Any) – 
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]
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].
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 = 10, **kwargs: Any) → List[Tuple[Document, float]][source]¶
Pass through to knn_search including score
Parameters
query (str) – 
k (int) – 
kwargs (Any) – 
Return type
List[Tuple[Document, float]]
langchain_chroma.vectorstores.cosine_similarity¶
langchain_chroma.vectorstores.cosine_similarity(X: Union[List[List[float]], List[ndarray], ndarray], Y: Union[List[List[float]], List[ndarray], ndarray]) → ndarray[source]¶
Row-wise cosine similarity between two equal-width matrices.
Raises
ValueError – If the number of columns in X and Y are not the same.
Parameters
X (Union[List[List[float]], List[ndarray], ndarray]) – 
Y (Union[List[List[float]], List[ndarray], ndarray]) – 
Return type
ndarray
Examples using cosine_similarity¶
How to route between sub-chains
langchain_community.vectorstores.elasticsearch.SparseRetrievalStrategy¶
class langchain_community.vectorstores.elasticsearch.SparseRetrievalStrategy(model_id: Optional[str] = None)[source]¶
[Deprecated] Sparse retrieval strategy using the text_expansion processor.
Notes
Deprecated since version 0.0.27: Use Use class in langchain-elasticsearch package instead.
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.
Parameters
model_id (Optional[str]) – 
__init__(model_id: Optional[str] = None)[source]¶
Parameters
model_id (Optional[str]) – 
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 (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]¶
Executes when the index is created.
Parameters
dims_length (Optional[int]) – Numeric length of the embedding vectors,
or None if not using vector-based query.
or None if not using vector-based query.
vector_query_field (str) – The field containing the vector
representations in the index.
similarity (Optional[DistanceStrategy]) – The similarity strategy to use,
or None if not using one.
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 (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 (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[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
langchain_elasticsearch.vectorstores.ExactRetrievalStrategy¶
class langchain_elasticsearch.vectorstores.ExactRetrievalStrategy(*args, **kwargs)[source]¶
[Deprecated] Exact retrieval strategy using the script_score query.
Notes
Deprecated since version 0.2.0: Use DenseVectorScriptScoreStrategy 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, text_field: str, similarity: Optional[DistanceStrategy]) → Dict[source]¶
Create the mapping for the Elasticsearch index.
Parameters
dims_length (Optional[int]) – 
vector_query_field (str) – 
text_field (str) –
vector_query_field (str) – 
text_field (str) – 
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.vdms.VDMS_Client¶
langchain_community.vectorstores.vdms.VDMS_Client(host: str = 'localhost', port: int = 55555) → vdms.vdms[source]¶
VDMS client for the VDMS server.
Parameters
host (str) – IP or hostname of VDMS server
port (int) – Port to connect to VDMS server
Return type
vdms.vdms
Examples using VDMS_Client¶
Intel’s Visual Data Management System (VDMS)
VDMS
langchain_community.vectorstores.apache_doris.ApacheDorisSettings¶
class langchain_community.vectorstores.apache_doris.ApacheDorisSettings[source]¶
Bases: BaseSettings
Apache Doris client configuration.
apache_doris_host¶
An URL to connect to frontend.
Defaults to ‘localhost’.
Type
str
apache_doris_port¶
URL port to connect with HTTP. Defaults to 9030.
Type
int
username¶
Username to login. Defaults to ‘root’.
Type
str
password¶
Password to login. Defaults to None.
Type
str
database¶
Database name to find the table. Defaults to ‘default’.
Type
str
table¶
Table name to operate on.
Defaults to ‘langchain’.
Type
str
column_map¶
Column type map to project column name onto langchain
semantics. Must have keys: text, id, vector,
must be same size to number of columns. For example:
.. code-block:: python
{‘id’: ‘text_id’,
‘embedding’: ‘text_embedding’,
‘document’: ‘text_plain’,
‘metadata’: ‘metadata_dictionary_in_json’,
}
Defaults to identity map.
Type
Dict
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 column_map: Dict[str, str] = {'document': 'document', 'embedding': 'embedding', 'id': 'id', 'metadata': 'metadata'}¶
param database: str = 'default'¶
param host: str = 'localhost'¶
param password: str = ''¶
param port: int = 9030¶
param table: str = 'langchain'¶
param username: str = 'root'¶
param username: str = 'root'¶
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
Parameters
_fields_set (Optional[SetStr]) – 
values (Any) – 
Return type
Model
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 (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – 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 (bool) – set to True to make a deep copy of the model
self (Model) – 
Returns
new model instance
Return type
Model
ref_template (unicode) – 
Return type
DictStrAny
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
dumps_kwargs (Any) – 
Return type
unicode
classmethod update_forward_refs(**localns: Any) → None¶
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
Model
Examples using ApacheDorisSettings¶
Apache Doris