langchain_community.vectorstores.tigris.Tigris

class langchain_community.vectorstores.tigris.Tigris(client: TigrisClient, embeddings: Embeddings, index_name: str)[source]

Tigris 向量存储。

初始化 Tigris 向量存储。

属性

embeddings

如果可用,访问查询嵌入对象。

search_index

方法

__init__(client, embeddings, index_name)

初始化 Tigris 向量存储。

aadd_documents(documents, **kwargs)

异步地通过嵌入运行更多文档并添加到向量存储中。

aadd_texts(texts[, metadatas])

异步地通过嵌入运行更多文本并添加到向量存储中。

add_documents(documents, **kwargs)

在向量存储中添加或更新文档。

add_texts(texts[, metadatas, ids])

通过嵌入运行更多文本并添加到向量存储中。

adelete([ids])

通过向量 ID 或其他条件异步删除。

afrom_documents(documents, embedding, **kwargs)

异步地从文档和嵌入初始化并返回 VectorStore。

afrom_texts(texts, embedding[, metadatas])

异步地从文本和嵌入初始化并返回 VectorStore。

aget_by_ids(ids, /)

通过 ID 异步获取文档。

amax_marginal_relevance_search(query[, k, ...])

异步地返回使用最大边际相关性选择的文档。

amax_marginal_relevance_search_by_vector(...)

异步地返回使用最大边际相关性选择的文档。

as_retriever(**kwargs)

返回从该 VectorStore 初始化而来的 VectorStoreRetriever。

asearch(query, search_type, **kwargs)

异步地返回与使用指定搜索类型查询最相似的文档。

asimilarity_search(query[, k])

异步地返回与查询最相似的文档。

asimilarity_search_by_vector(embedding[, k])

异步地返回与嵌入向量最相似的文档。

asimilarity_search_with_relevance_scores(query)

异步地返回文档和相关性评分,范围为 [0, 1]。

asimilarity_search_with_score(*args, **kwargs)

异步地运行带距离的相似性搜索。

astreaming_upsert(items, /, batch_size, **kwargs)

aupsert(items, /, **kwargs)

delete([ids])

通过向量 ID 或其他条件删除。

from_documents(documents, embedding, **kwargs)

从文档和嵌入初始化并返回 VectorStore。

from_texts(texts, embedding[, metadatas, ...])

从文本和嵌入初始化并返回 VectorStore。

get_by_ids(ids, /)

通过 ID 获取文档。

max_marginal_relevance_search(query[, k, ...])

返回使用最大边际相关性选择的文档。

max_marginal_relevance_search_by_vector(...)

返回使用最大边际相关性选择的文档。

search(query, search_type, **kwargs)

返回与使用指定搜索类型查询最相似的文档。

similarity_search(query[, k, filter])

返回与查询最相似的文档。

similarity_search_by_vector(embedding[, k])

返回与嵌入向量最相似的文档。

similarity_search_with_relevance_scores(query)

返回文档和相关性评分,范围为 [0, 1]。

similarity_search_with_score(query[, k, filter])

使用 Chroma 运行带距离的相似性搜索。

streaming_upsert(items, /, batch_size, **kwargs)

upsert(items, /, **kwargs)

参数
  • client (TigrisClient) –

  • embeddings (Embeddings) –

  • index_name (str) –

__init__(client: TigrisClient, embeddings: Embeddings, index_name: str)[source]

初始化 Tigris 向量存储。

参数
  • client (TigrisClient) –

  • embeddings (Embeddings) –

  • index_name (str) –

async aadd_documents(documents: List[Document], **kwargs: Any) List[str]

异步地通过嵌入运行更多文档并添加到向量存储中。

参数
  • documents (List[Document]) – 要添加到向量存储的文档列表。

  • kwargs (Any) – 额外的关键字参数。

返回

添加文本的 ID 列表。

Raises

ValueError – 如果 ID 数量与文档数量不匹配,则引发 ValueError 异常。

Return type

List[str]

async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) List[str]

异步地通过嵌入运行更多文本并添加到向量存储中。

参数
  • texts (Iterable[str]) – 要添加到向量存储的字符串可迭代对象。

  • metadatas (Optional[List[dict]]) – 与文本关联的可选元数据列表。默认为 None。

  • **kwargs (Any) – 向量存储特定的参数。

返回

从将文本添加到向量存储中获取的 id 列表。

Raises
  • ValueError – 如果元数据数量与文本数量不匹配,则引发 ValueError 异常。

  • ValueError – 如果 id 数量与文本数量不匹配,则引发 ValueError 异常。

Return type

List[str]

add_documents(documents: List[Document], **kwargs: Any) List[str]

在向量存储中添加或更新文档。

参数
  • documents (List[Document]) – 要添加到向量存储的文档列表。

  • kwargs (Any) – 额外的关键字参数。如果 kwargs 包含 ids 且 documents 包含 ids,则 kwargs 中的 ids 将优先。

返回

添加文本的 ID 列表。

Raises

ValueError – 如果 id 数量与文档数量不匹配,则引发 ValueError 异常。

Return type

List[str]

add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) List[str][source]

通过嵌入运行更多文本并添加到向量存储中。

参数
  • texts (Iterable[str]) – 要添加到向量存储的字符串可迭代对象。

  • metadatas (Optional[List[dict]]) – 与文本关联的可选元数据列表。

  • ids (Optional[List[str]]) – 文档的可选 id 列表。如果未提供,将自动生成 ID。

  • kwargs (Any) – 向量存储特定的参数

返回

从将文本添加到向量存储中获取的 id 列表。

Return type

List[str]

async adelete(ids: Optional[List[str]] = None, **kwargs: Any) Optional[bool]

通过向量 ID 或其他条件异步删除。

参数
  • ids (Optional[List[str]]) – 要删除的 id 列表。如果为 None,则删除全部。默认为 None。

  • **kwargs (Any) – 子类可能使用的其他关键字参数。

返回

如果删除成功,则返回 True,否则返回 False;如果未实现,则返回 None。

Return type

Optional[bool]

async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) VST

异步地从文档和嵌入初始化并返回 VectorStore。

参数
  • documents (List[Document]) – 要添加到向量存储的文档列表。

  • embedding (Embeddings) – 要使用的嵌入函数。

  • kwargs (Any) – 额外的关键字参数。

返回

从文档和嵌入初始化的 VectorStore。

Return type

VectorStore

async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) VST

异步地从文本和嵌入初始化并返回 VectorStore。

参数
  • texts (List[str]) – 要添加到向量存储的文本列表。

  • embedding (Embeddings) – 要使用的嵌入函数。

  • metadatas (Optional[List[dict]]) – 与文本关联的可选元数据列表。默认为 None。

  • kwargs (Any) – 额外的关键字参数。

返回

从文本和嵌入初始化的 VectorStore。

Return type

VectorStore

async aget_by_ids(ids: Sequence[str], /) List[Document]

通过 ID 异步获取文档。

返回的文档应将 ID 字段设置为向量存储中文档的 ID。

如果某些 ID 未找到或存在重复的 ID,则返回的文档可能少于请求的文档。

用户不应假设返回文档的顺序与输入 ID 的顺序匹配。相反,用户应依赖返回文档的 ID 字段。

如果对于某些 ID 未找到文档,此方法应引发异常。

参数

ids (Sequence[str]) – 要检索的 id 列表。

返回

文档列表。

Return type

List[Document]

0.2.11 版本新增。

异步地返回使用最大边际相关性选择的文档。

最大边际相关性优化了与查询的相似性以及所选文档之间的多样性。

参数
  • query (str) – 用于查找相似文档的文本。

  • k (int) – 要返回的文档数量。默认为 4。

  • fetch_k (int) – 要获取以传递给 MMR 算法的文档数量。默认为 20。

  • lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,其中 0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。

  • kwargs (Any) –

返回

通过最大边际相关性选择的文档列表。

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]

异步地返回使用最大边际相关性选择的文档。

最大边际相关性优化了与查询的相似性以及所选文档之间的多样性。

参数
  • embedding (List[float]) – 用于查找相似文档的嵌入向量。

  • k (int) – 要返回的文档数量。默认为 4。

  • fetch_k (int) – 要获取以传递给 MMR 算法的文档数量。默认为 20。

  • lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,其中 0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。

  • **kwargs (Any) – 传递给搜索方法的参数。

返回

通过最大边际相关性选择的文档列表。

Return type

List[Document]

as_retriever(**kwargs: Any) VectorStoreRetriever

返回从该 VectorStore 初始化而来的 VectorStoreRetriever。

参数

**kwargs (Any) –

传递给搜索函数的关键字参数。可以包括:search_type (Optional[str]):定义检索器应执行的搜索类型。

可以是“similarity”(默认)、“mmr”或“similarity_score_threshold”。

search_kwargs (Optional[Dict]):传递给搜索函数的关键字参数。可以包括如下内容
搜索函数。可以包括如下内容

k:要返回的文档数量(默认值:4) score_threshold:相似度分数阈值的最小相关性阈值

用于相似度分数阈值

fetch_k:要传递给 MMR 算法的文档数量

(默认值:20)

lambda_mult:MMR 返回结果的多样性;

1 表示最小多样性,0 表示最大多样性。(默认值:0.5)

filter:按文档元数据筛选

返回

VectorStore 的检索器类。

Return type

VectorStoreRetriever

示例

# 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
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]

异步地返回与使用指定搜索类型查询最相似的文档。

参数
  • query (str) – 输入文本。

  • search_type (str) – 要执行的搜索类型。可以是“similarity”、“mmr”或“similarity_score_threshold”。

  • **kwargs (Any) – 传递给搜索方法的参数。

返回

与查询最相似的文档列表。

Raises

ValueError – 如果 search_type 不是“similarity”、“mmr”或“similarity_score_threshold”之一,则引发 ValueError 异常。

Return type

List[Document]

异步地返回与查询最相似的文档。

参数
  • query (str) – 输入文本。

  • k (int) – 要返回的文档数量。默认为 4。

  • **kwargs (Any) – 传递给搜索方法的参数。

返回

与查询最相似的文档列表。

Return type

List[Document]

async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) List[Document]

异步地返回与嵌入向量最相似的文档。

参数
  • embedding (List[float]) – 用于查找相似文档的嵌入向量。

  • k (int) – 要返回的文档数量。默认为 4。

  • **kwargs (Any) – 传递给搜索方法的参数。

返回

最不相似于查询向量的文档列表。

Return type

List[Document]

async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) List[Tuple[Document, float]]

异步地返回文档和相关性评分,范围为 [0, 1]。

0 表示不相似,1 表示最相似。

参数
  • query (str) – 输入文本。

  • k (int) – 要返回的文档数量。默认为 4。

  • **kwargs (Any) –

    传递给相似性搜索的 kwargs。应包括:score_threshold:可选,介于 0 到 1 之间的浮点数值,用于

    过滤检索到的文档结果集

返回

(doc, similarity_score) 元组的列表

Return type

List[Tuple[Document, float]]

async asimilarity_search_with_score(*args: Any, **kwargs: Any) List[Tuple[Document, float]]

异步地运行带距离的相似性搜索。

参数
  • *args (Any) – 传递给搜索方法的参数。

  • **kwargs (Any) – 传递给搜索方法的参数。

返回

(doc, similarity_score) 元组的列表。

Return type

List[Tuple[Document, float]]

astreaming_upsert(items: AsyncIterable[Document], /, batch_size: int, **kwargs: Any) AsyncIterator[UpsertResponse]

Beta

添加于 0.2.11。API 可能会更改。

以流式方式更新文档。streaming_upsert 的异步版本。

参数
  • items (AsyncIterable[Document]) – 要添加到向量存储的文档的可迭代对象。

  • batch_size (int) – 每次更新批处理的大小。

  • kwargs (Any) – 额外的关键字参数。kwargs 应仅包含所有文档通用的参数。(例如,索引超时,重试策略等。)kwargs 不应包含 ID 以避免语义模糊。而是应将 ID 作为 Document 对象的一部分提供。

Yields

UpsertResponse – 包含已成功添加到或更新到向量存储中的 ID 列表以及未能添加或更新的 ID 列表的响应对象。

Return type

AsyncIterator[UpsertResponse]

0.2.11 版本新增。

async aupsert(items: Sequence[Document], /, **kwargs: Any) UpsertResponse

Beta

添加于 0.2.11。API 可能会更改。

在向量存储中添加或更新文档。upsert 的异步版本。

如果提供了文档对象的 ID 字段,则 upsert 功能应使用它。如果未提供 ID,则 upsert 方法可以自由地为文档生成 ID。

当指定了 ID 且文档已存在于向量存储中时,upsert 方法应使用新数据更新文档。如果文档不存在,则 upsert 方法应将文档添加到向量存储中。

参数
  • items (Sequence[Document]) – 要添加到向量存储的文档序列。

  • kwargs (Any) – 额外的关键字参数。

返回

包含已成功添加到或更新到向量存储中的 ID 列表以及未能添加或更新的 ID 列表的响应对象。

Return type

UpsertResponse

0.2.11 版本新增。

delete(ids: Optional[List[str]] = None, **kwargs: Any) Optional[bool]

通过向量 ID 或其他条件删除。

参数
  • ids (Optional[List[str]]) – 要删除的 id 列表。如果为 None,则删除全部。默认为 None。

  • **kwargs (Any) – 子类可能使用的其他关键字参数。

返回

如果删除成功,则返回 True,否则返回 False;如果未实现,则返回 None。

Return type

Optional[bool]

classmethod from_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) VST

从文档和嵌入初始化并返回 VectorStore。

参数
  • documents (List[Document]) – 要添加到向量存储的文档列表。

  • embedding (Embeddings) – 要使用的嵌入函数。

  • kwargs (Any) – 额外的关键字参数。

返回

从文档和嵌入初始化的 VectorStore。

Return type

VectorStore

classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, client: Optional[TigrisClient] = None, index_name: Optional[str] = None, **kwargs: Any) Tigris[source]

从文本和嵌入初始化并返回 VectorStore。

参数
  • texts (List[str]) –

  • embedding (Embeddings) –

  • metadatas (Optional[List[dict]]) –

  • ids (Optional[List[str]]) –

  • client (Optional[TigrisClient]) –

  • index_name (Optional[str]) –

  • kwargs (Any) –

Return type

Tigris

get_by_ids(ids: Sequence[str], /) List[Document]

通过 ID 获取文档。

返回的文档应将 ID 字段设置为向量存储中文档的 ID。

如果某些 ID 未找到或存在重复的 ID,则返回的文档可能少于请求的文档。

用户不应假设返回文档的顺序与输入 ID 的顺序匹配。相反,用户应依赖返回文档的 ID 字段。

如果对于某些 ID 未找到文档,此方法应引发异常。

参数

ids (Sequence[str]) – 要检索的 id 列表。

返回

文档列表。

Return type

List[Document]

0.2.11 版本新增。

返回使用最大边际相关性选择的文档。

最大边际相关性优化了与查询的相似性以及所选文档之间的多样性。

参数
  • query (str) – 用于查找相似文档的文本。

  • k (int) – 要返回的文档数量。默认为 4。

  • fetch_k (int) – 要获取以传递给 MMR 算法的文档数量。默认为 20。

  • lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,其中 0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。

  • **kwargs (Any) – 传递给搜索方法的参数。

返回

通过最大边际相关性选择的文档列表。

Return type

List[Document]

max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) List[Document]

返回使用最大边际相关性选择的文档。

最大边际相关性优化了与查询的相似性以及所选文档之间的多样性。

参数
  • embedding (List[float]) – 用于查找相似文档的嵌入向量。

  • k (int) – 要返回的文档数量。默认为 4。

  • fetch_k (int) – 要获取以传递给 MMR 算法的文档数量。默认为 20。

  • lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,其中 0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。

  • **kwargs (Any) – 传递给搜索方法的参数。

返回

通过最大边际相关性选择的文档列表。

Return type

List[Document]

search(query: str, search_type: str, **kwargs: Any) List[Document]

返回与使用指定搜索类型查询最相似的文档。

参数
  • query (str) – 输入文本

  • search_type (str) – 要执行的搜索类型。可以是“similarity”、“mmr”或“similarity_score_threshold”。

  • **kwargs (Any) – 传递给搜索方法的参数。

返回

与查询最相似的文档列表。

Raises

ValueError – 如果 search_type 不是“similarity”、“mmr”或“similarity_score_threshold”之一,则引发 ValueError 异常。

Return type

List[Document]

返回与查询最相似的文档。

参数
  • query (str) –

  • k (int) –

  • filter (Optional[TigrisFilter]) –

  • kwargs (Any) –

Return type

List[Document]

similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) List[Document]

返回与嵌入向量最相似的文档。

参数
  • embedding (List[float]) – 用于查找相似文档的嵌入向量。

  • k (int) – 要返回的文档数量。默认为 4。

  • **kwargs (Any) – 传递给搜索方法的参数。

返回

最不相似于查询向量的文档列表。

Return type

List[Document]

similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) List[Tuple[Document, float]]

返回文档和相关性评分,范围为 [0, 1]。

0 表示不相似,1 表示最相似。

参数
  • query (str) – 输入文本。

  • k (int) – 要返回的文档数量。默认为 4。

  • **kwargs (Any) –

    传递给相似性搜索的 kwargs。应包括:score_threshold:可选,介于 0 到 1 之间的浮点数值,用于

    过滤检索到的文档结果集。

返回

(doc, similarity_score) 元组的列表。

Return type

List[Tuple[Document, float]]

similarity_search_with_score(query: str, k: int = 4, filter: Optional[TigrisFilter] = None) List[Tuple[Document, float]][source]

使用 Chroma 运行带距离的相似性搜索。

参数
  • query (str) – 要搜索的查询文本。

  • k (int) – 要返回的结果数。默认为 4。

  • filter (Optional[TigrisFilter]) – 按元数据过滤。默认为 None。

返回

最接近查询文本的文档列表,带有浮点距离。

文本距离浮点数表示。

Return type

List[Tuple[Document, float]]

streaming_upsert(items: Iterable[Document], /, batch_size: int, **kwargs: Any) Iterator[UpsertResponse]

Beta

添加于 0.2.11。API 可能会更改。

以流式方式更新文档。

参数
  • items (Iterable[Document]) – 要添加到向量存储的文档的可迭代对象。

  • batch_size (int) – 每次更新批处理的大小。

  • kwargs (Any) – 额外的关键字参数。kwargs 应仅包含所有文档通用的参数。(例如,索引超时,重试策略等。)kwargs 不应包含 ID 以避免语义模糊。而是,应将 ID 作为 Document 对象的一部分提供。

Yields

UpsertResponse – 包含已成功添加到或更新到向量存储中的 ID 列表以及未能添加或更新的 ID 列表的响应对象。

Return type

Iterator[UpsertResponse]

0.2.11 版本新增。

upsert(items: Sequence[Document], /, **kwargs: Any) UpsertResponse

Beta

添加于 0.2.11。API 可能会更改。

在向量存储中添加或更新文档。

如果提供了文档对象的 ID 字段,则 upsert 功能应使用它。如果未提供 ID,则 upsert 方法可以自由地为文档生成 ID。

当指定了 ID 且文档已存在于向量存储中时,upsert 方法应使用新数据更新文档。如果文档不存在,则 upsert 方法应将文档添加到向量存储中。

参数
  • items (Sequence[Document]) – 要添加到向量存储的文档序列。

  • kwargs (Any) – 额外的关键字参数。

返回

包含已成功添加到或更新到向量存储中的 ID 列表以及未能添加或更新的 ID 列表的响应对象。

Return type

UpsertResponse

0.2.11 版本新增。

使用 Tigris 的示例