Tony20100/langchain_full huggingface dataset:
The embeddings will be generated using embedding class provided.
Order of elements for lists ids, texts, metadatas should match,
so each row will be associated with correct values.
Postgres connection string is required
“Either pass it as connection_string parameter
or set the LANTERN_CONNECTION_STRING environment variable.
connection_string is fully populated connection string for postgres database
texts texts to insert into collection.
embedding is Embeddings that will be used forembedding the text sent. If none is sent, then the
multilingual Tensorflow Universal Sentence Encoder will be used.
metadatas row metadata to insert into collection.
collection_name is the name of the collection to use. (default: langchain)
NOTE: This is the name of the table in which embedding data will be storedThe table will be created when initializing the store (if not exists)
So, make sure the user has the right permissions to create tables.
distance_strategy is the distance strategy to use. (default: EUCLIDEAN)
EUCLIDEAN is the euclidean distance.
COSINE is the cosine distance.
HAMMING is the hamming distance.
ids row ids to insert into collection.
pre_delete_collection if True, will delete the collection if it exists.(default: False)
- Useful for testing.
Parameters
texts (List[str]) – 
embedding (Embeddings) – 
metadatas (Optional[List[dict]]) – 
collection_name (str) – 
distance_strategy (DistanceStrategy) – 
ids (Optional[List[str]]) – 
pre_delete_collection (bool) – 
kwargs (Any) – 
Return type
Lantern
kwargs (Any) – 
Return type
Lantern
max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, str]] = 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.
Defaults to 20.
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[str, str]]) – Filter by metadata. Defaults to None.
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[str, str]] = None, **kwargs: Any) → List[Document][source]¶
Return docs selected using the maximal marginal relevanceto embedding vector.
Maximal marginal relevance optimizes for similarity to query AND diversityamong selected documents.
Parameters
embedding (str) – Text to look up documents similar to.
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.
Defaults to 20.
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[str, str]]) – Filter by metadata. Defaults to None.
kwargs (Any) – 
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[Document]
max_marginal_relevance_search_with_score(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[dict] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
Return docs selected using the maximal marginal relevance with score.
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.
Defaults to 20.
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[str, str]]) – Filter by metadata. Defaults to None.
kwargs (Any) – 
Returns
List of Documents selected by maximal marginalrelevance to the query and score for each.
Return type
List[Tuple[Document, float]]
Return type
List[Tuple[Document, float]]
max_marginal_relevance_search_with_score_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, str]] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
Return docs selected using the maximal marginal relevance with scoreto embedding vector.
Maximal marginal relevance optimizes for similarity to query AND diversityamong 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.
Defaults to 20.
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[str, str]]) – Filter by metadata. Defaults to None.
kwargs (Any) – 
Returns
List of Documents selected by maximal marginalrelevance to the query and score for each.
Return type
List[Tuple[Document, float]]
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]
Return type
List[Document]
similarity_search(query: str, k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[Document][source]¶
Return docs most similar to query.
Parameters
query (str) – Input text.
k (int) – Number of Documents to return. Defaults to 4.
filter (Optional[dict]) – 
kwargs (Any) – 
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, **kwargs: Any) → 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]) – 
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].
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]]
Return type
List[Tuple[Document, float]]
similarity_search_with_score(query: str, k: int = 4, filter: Optional[dict] = None) → List[Tuple[Document, float]][source]¶
Run similarity search with distance.
Returns
List of Tuples of (doc, similarity_score)
Parameters
query (str) – 
k (int) – 
filter (Optional[dict]) – 
Return type
List[Tuple[Document, float]]
similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None) → List[Tuple[Document, float]][source]¶
Parameters
embedding (List[float]) – 
k (int) – 
filter (Optional[dict]) – 
Return type
List[Tuple[Document, float]]
Examples using Lantern¶
Lantern
add_documents(documents, **kwargs)
Run more documents through the embeddings and add to the vectorstore.
add_texts(texts[, metadatas, ...])
Embed texts and add them to the database.
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)
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.
clear_data([collection_name])
Clear data in a collection.
delete([ids])
Delete by vector ID or other criteria.
from_documents(documents, embedding[, ...])
Create an Epsilla vectorstore from a list of documents.
from_texts(texts, embedding[, metadatas, ...])
Create an Epsilla vectorstore from raw documents.
get([collection_name, response_fields])
Get the collection.
get([collection_name, response_fields])
Get the collection.
max_marginal_relevance_search(query[, k, ...])
Return docs selected using the maximal marginal relevance.
max_marginal_relevance_search_by_vector(...)
Return docs selected using the maximal marginal relevance.
search(query, search_type, **kwargs)
Return docs most similar to query using specified search type.
similarity_search(query[, k, collection_name])
Return the documents that are semantically most relevant to the query.
similarity_search_by_vector(embedding[, k])
Return docs most similar to embedding vector.
similarity_search_with_relevance_scores(query)
Return docs and relevance scores in the range [0, 1].
similarity_search_with_score(*args, **kwargs)
Run similarity search with distance.
use_collection(collection_name)
Set default collection to use.
__init__(client: Any, embeddings: Embeddings, db_path: Optional[str] = '/tmp/langchain-epsilla', db_name: Optional[str] = 'langchain_store')[source]¶
Initialize with necessary components.
Parameters
client (Any) – 
embeddings (Embeddings) – 
db_path (Optional[str]) – 
db_name (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
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, collection_name: Optional[str] = '', drop_old: Optional[bool] = False, **kwargs: Any) → List[str][source]¶
Embed texts and add them to the database.
Parameters
texts (Iterable[str]) – The texts to embed.
metadatas (Optional[List[dict]]) – Metadata dicts
attached to each of the texts. Defaults to None.
collection_name (Optional[str]) – Which collection to use.
Defaults to “langchain_collection”.
If provided, default collection name will be set as well.
drop_old (Optional[bool]) – Whether to drop the previous collection
and create a new one. Defaults to False.
kwargs (Any) – 
Returns
List of ids of 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]]
clear_data(collection_name: str = '') → None[source]¶
Clear data in a collection.
Parameters
collection_name (Optional[str]) – The name of the collection.
If not provided, the default collection will be used.
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, client: Optional[Any] = None, db_path: Optional[str] = '/tmp/langchain-epsilla', db_name: Optional[str] = 'langchain_store', collection_name: Optional[str] = 'langchain_collection', drop_old: Optional[bool] = False, **kwargs: Any) → Epsilla[source]¶
Create an Epsilla vectorstore from a list of documents.
Parameters
texts (List[str]) – List of text data to be inserted.
embeddings (Embeddings) – Embedding function.
embeddings (Embeddings) – Embedding function.
client (pyepsilla.vectordb.Client) – Epsilla client to connect to.
metadatas (Optional[List[dict]]) – Metadata for each text.
Defaults to None.
db_path (Optional[str]) – The path where the database will be persisted.
Defaults to “/tmp/langchain-epsilla”.
db_name (Optional[str]) – Give a name to the loaded database.
Defaults to “langchain_store”.
collection_name (Optional[str]) – Which collection to use.
Defaults to “langchain_collection”.
If provided, default collection name will be set as well.
drop_old (Optional[bool]) – Whether to drop the previous collection
and create a new one. Defaults to False.
documents (List[Document]) – 
embedding (Embeddings) – 
kwargs (Any) – 
Returns
Epsilla vector store.
Return type
Epsilla
classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, client: Optional[Any] = None, db_path: Optional[str] = '/tmp/langchain-epsilla', db_name: Optional[str] = 'langchain_store', collection_name: Optional[str] = 'langchain_collection', drop_old: Optional[bool] = False, **kwargs: Any) → Epsilla[source]¶
Create an Epsilla vectorstore from raw documents.
Parameters
texts (List[str]) – List of text data to be inserted.
embeddings (Embeddings) – Embedding function.
client (pyepsilla.vectordb.Client) – Epsilla client to connect to.
metadatas (Optional[List[dict]]) – Metadata for each text.
Defaults to None.
Defaults to None.
db_path (Optional[str]) – The path where the database will be persisted.
Defaults to “/tmp/langchain-epsilla”.
db_name (Optional[str]) – Give a name to the loaded database.
Defaults to “langchain_store”.
collection_name (Optional[str]) – Which collection to use.
Defaults to “langchain_collection”.
If provided, default collection name will be set as well.
drop_old (Optional[bool]) – Whether to drop the previous collection
and create a new one. Defaults to False.
embedding (Embeddings) – 
kwargs (Any) – 
Returns
Epsilla vector store.
Return type
Epsilla
get(collection_name: str = '', response_fields: Optional[List[str]] = None) → List[dict][source]¶
Get the collection.
Parameters
collection_name (Optional[str]) – The name of the collection
to retrieve data from.
If not provided, the default collection will be used.
response_fields (Optional[List[str]]) – List of field names in the result.
If not specified, all available fields will be responded.
Returns
A list of the retrieved data.
Return type
List[dict]
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.
Return type
List[Document]
similarity_search(query: str, k: int = 4, collection_name: str = '', **kwargs: Any) → List[Document][source]¶
Return the documents that are semantically most relevant to the query.
Parameters
query (str) – String to query the vectorstore with.
k (Optional[int]) – Number of documents to return. Defaults to 4.
collection_name (Optional[str]) – Collection to use.
Defaults to “langchain_store” or the one provided before.
kwargs (Any) – 
Returns
List of documents that are semantically most relevant to the query
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].
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(*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]]
use_collection(collection_name: str) → None[source]¶
Set default collection to use.
Parameters
collection_name (str) – The name of the collection.
Return type
None
Examples using Epsilla¶
Epsilla
langchain_community.vectorstores.awadb.AwaDB¶
class langchain_community.vectorstores.awadb.AwaDB(table_name: str = 'langchain_awadb', embedding: Optional[Embeddings] = None, log_and_data_dir: Optional[str] = None, client: Optional[awadb.Client] = None, **kwargs: Any)[source]¶
AwaDB vector store.
Initialize with AwaDB client.If table_name is not specified,
a random table name of _DEFAULT_TABLE_NAME + last segment of uuid
would be created automatically.
Parameters
table_name (str) – Name of the table created, default _DEFAULT_TABLE_NAME.
embedding (Optional[Embeddings]) – Optional Embeddings initially set.
log_and_data_dir (Optional[str]) – Optional the root directory of log and data.
client (Optional[awadb.Client]) – Optional AwaDB client.
kwargs (Any) – Any possible extend parameters in the future.
Returns
None.
Attributes
embeddings
Access the query embedding object if available.
Methods
__init__([table_name, embedding, ...])
Initialize with AwaDB client.
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, is_duplicate_texts])
Run more texts through the embeddings and add to the vectorstore.
adelete([ids])
Delete by vector ID or other criteria.
afrom_documents(documents, embedding, **kwargs)
Return VectorStore initialized from documents and embeddings.
Return VectorStore initialized from documents and embeddings.
afrom_texts(texts, embedding[, metadatas])
Return VectorStore initialized from texts and embeddings.
amax_marginal_relevance_search(query[, k, ...])
Return docs selected using the maximal marginal relevance.
amax_marginal_relevance_search_by_vector(...)
Return docs selected using the maximal marginal relevance.
as_retriever(**kwargs)
Return VectorStoreRetriever initialized from this VectorStore.
asearch(query, search_type, **kwargs)
Return docs most similar to query using specified search type.
asimilarity_search(query[, k])
Return docs most similar to query.
asimilarity_search_by_vector(embedding[, k])
Return docs most similar to embedding vector.
asimilarity_search_with_relevance_scores(query)
Return docs and relevance scores in the range [0, 1].
asimilarity_search_with_score(*args, **kwargs)
Run similarity search with distance.
create_table(table_name, **kwargs)
Create a new table.
delete([ids])
Delete the documents which have the specified ids.
from_documents(documents[, embedding, ...])
Create an AwaDB vectorstore from a list of documents.
from_texts(texts[, embedding, metadatas, ...])
Create an AwaDB vectorstore from a raw documents.
get([ids, text_in_page_content, ...])
Return docs according ids.
get_current_table(**kwargs)
Get the current table.
list_tables(**kwargs)
List all the tables created by the client.
load_local(table_name, **kwargs)
Load the local specified table.
max_marginal_relevance_search(query[, k, ...])
Return docs selected using the maximal marginal relevance.
Return docs selected using the maximal marginal relevance.
max_marginal_relevance_search_by_vector(...)
Return docs selected using the maximal marginal relevance.
search(query, search_type, **kwargs)
Return docs most similar to query using specified search type.
similarity_search(query[, k, ...])
Return docs most similar to query.
similarity_search_by_vector([embedding, k, ...])
Return docs most similar to embedding vector.
similarity_search_with_relevance_scores(query)
Return docs and relevance scores in the range [0, 1].
similarity_search_with_score(query[, k, ...])
The most k similar documents and scores of the specified query.
update(ids, texts[, metadatas])
Update the documents which have the specified ids.
use(table_name, **kwargs)
Use the specified table.
__init__(table_name: str = 'langchain_awadb', embedding: Optional[Embeddings] = None, log_and_data_dir: Optional[str] = None, client: Optional[awadb.Client] = None, **kwargs: Any) → None[source]¶
Initialize with AwaDB client.If table_name is not specified,
a random table name of _DEFAULT_TABLE_NAME + last segment of uuid
would be created automatically.
Parameters
table_name (str) – Name of the table created, default _DEFAULT_TABLE_NAME.
embedding (Optional[Embeddings]) – Optional Embeddings initially set.
log_and_data_dir (Optional[str]) – Optional the root directory of log and data.
client (Optional[awadb.Client]) – Optional AwaDB client.
kwargs (Any) – Any possible extend parameters in the future.
Returns
None.
Return type
None
async aadd_documents(documents: List[Document], **kwargs: Any) → List[str]¶