langchain_community.vectorstores.documentdb.DocumentDBVectorSearch

class langchain_community.vectorstores.documentdb.DocumentDBVectorSearch(collection: Collection[DocumentDBDocumentType], embedding: Embeddings, *, index_name: str = 'vectorSearchIndex', text_key: str = 'textContent', embedding_key: str = 'vectorContent')[source]

Amazon DocumentDB (兼容 MongoDB) 向量存储。请参考官方向量搜索文档了解更多详情: https://docs.aws.amazon.com/documentdb/latest/developerguide/vector-search.html

要使用,您应该同时具备: - 已安装 pymongo python 包 - 与 DocumentDB 集群关联的连接字符串和凭据

示例

. code-block:: python

from langchain_community.vectorstores import DocumentDBVectorSearch from langchain_community.embeddings.openai import OpenAIEmbeddings from pymongo import MongoClient

mongo_client = MongoClient(“<YOUR-CONNECTION-STRING>”) collection = mongo_client[“<db_name>”][“<collection_name>”] embeddings = OpenAIEmbeddings() vectorstore = DocumentDBVectorSearch(collection, embeddings)

DocumentDBVectorSearch 的构造函数

参数
  • collection (Collection[DocumentDBDocumentType]) – 要将文本添加到的 MongoDB 集合。

  • embedding (Embeddings) – 要使用的文本嵌入模型。

  • index_name (str) – 向量搜索索引的名称。

  • text_key (str) – 将包含每个文档文本的 MongoDB 字段。

  • embedding_key (str) – 将包含每个文档嵌入向量的 MongoDB 字段。

属性

embeddings

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

方法

__init__(collection, embedding, *[, ...])

DocumentDBVectorSearch 的构造函数

aadd_documents(documents, **kwargs)

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

aadd_texts(texts[, metadatas])

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

add_documents(documents, **kwargs)

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

add_texts(texts[, metadatas])

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

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)

create_index([dimensions, similarity, m, ...])

使用指定的索引名称创建索引

delete([ids])

通过向量 ID 或其他标准删除。

delete_document_by_id([document_id])

通过 ID 删除特定文档

delete_index()

如果实例构造期间指定的索引存在,则删除该索引

from_connection_string(connection_string, ...)

从连接字符串创建 DocumentDBVectorSearch 实例

from_documents(documents, embedding, **kwargs)

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

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

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

get_by_ids(ids, /)

通过 ID 获取文档。

get_index_name()

返回索引名称

index_exists()

验证实例构造期间指定的索引名称是否存在

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

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

max_marginal_relevance_search_by_vector(...)

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

search(query, search_type, **kwargs)

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

similarity_search(query[, k, ef_search, filter])

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

similarity_search_by_vector(embedding[, k])

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

similarity_search_with_relevance_scores(query)

返回范围在 [0, 1] 内的文档和相关性得分。

similarity_search_with_score(*args, **kwargs)

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

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

upsert(items, /, **kwargs)

__init__(collection: Collection[DocumentDBDocumentType], embedding: Embeddings, *, index_name: str = 'vectorSearchIndex', text_key: str = 'textContent', embedding_key: str = 'vectorContent')[source]

DocumentDBVectorSearch 的构造函数

参数
  • collection (Collection[DocumentDBDocumentType]) – 要将文本添加到的 MongoDB 集合。

  • embedding (Embeddings) – 要使用的文本嵌入模型。

  • index_name (str) – 向量搜索索引的名称。

  • text_key (str) – 将包含每个文档文本的 MongoDB 字段。

  • embedding_key (str) – 将包含每个文档嵌入向量的 MongoDB 字段。

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

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

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

  • kwargs (Any) – 附加关键字参数。

返回

添加的文本的 ID 列表。

引发

ValueError – 如果 ID 数量与文档数量不匹配。

返回类型

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 列表。

引发
  • ValueError – 如果元数据数量与文本数量不匹配。

  • ValueError – 如果 id 数量与文本数量不匹配。

返回类型

List[str]

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

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

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

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

返回

添加的文本的 ID 列表。

引发

ValueError – 如果 id 数量与文档数量不匹配。

返回类型

List[str]

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

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

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

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

  • **kwargs (Any) – 向量存储特定的参数。kwargs 之一应该是 ids,它是与文本关联的 id 列表。

返回

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

引发
  • ValueError – 如果元数据数量与文本数量不匹配。

  • ValueError – 如果 id 数量与文本数量不匹配。

返回类型

List

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

通过向量 ID 或其他标准异步删除。

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

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

返回

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

返回类型

Optional[bool]

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

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

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

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

  • kwargs (Any) – 附加关键字参数。

返回

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

返回类型

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。

返回类型

VectorStore

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

异步通过 ID 获取文档。

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

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

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

如果某些 ID 没有找到文档,则此方法不应引发异常。

参数

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

返回

文档列表。

返回类型

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) –

返回

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

返回类型

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) – 传递给搜索方法的参数。

返回

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

返回类型

List[Document]

as_retriever(**kwargs: Any) VectorStoreRetriever

返回从该 VectorStore 初始化的 VectorStoreRetriever。

参数

**kwargs (Any) –

传递给搜索函数的关键字参数。可以包括: search_type (Optional[str]): 定义检索器应执行的搜索类型。可以是 “similarity”(默认)、“mmr” 或 “similarity_score_threshold”。

the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”.

search_kwargs (Optional[Dict]): 传递给
search function. Can include things like

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

for similarity_score_threshold

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

(Default: 20)

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

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

filter: 按文档元数据过滤

返回

VectorStore 的检索器类。

返回类型

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) – 传递给搜索方法的参数。

返回

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

引发

ValueError – 如果 search_type 不是 “similarity”、“mmr” 或 “similarity_score_threshold” 之一。

返回类型

List[Document]

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

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

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

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

返回

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

返回类型

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) – 传递给搜索方法的参数。

返回

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

返回类型

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 之间的浮点值,用于

    筛选检索到的文档结果集

返回

(文档,相似度分数)元组列表

返回类型

List[Tuple[Document, float]]

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

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

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

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

返回

(文档,相似度分数)元组列表。

返回类型

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 不应包含 ids 以避免语义模糊。相反,ID 应该作为 Document 对象的一部分提供。

Yields

UpsertResponse – 响应对象,其中包含向量存储中成功添加或更新的 ID 列表以及添加或更新失败的 ID 列表。

返回类型

AsyncIterator[UpsertResponse]

0.2.11 版本新增。

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

Beta 版本

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

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

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

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

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

  • kwargs (Any) – 附加关键字参数。

返回

响应对象,其中包含向量存储中成功添加或更新的 ID 列表以及添加或更新失败的 ID 列表。

返回类型

UpsertResponse

0.2.11 版本新增。

create_index(dimensions: int = 1536, similarity: DocumentDBSimilarityType = DocumentDBSimilarityType.COS, m: int = 16, ef_construction: int = 64) dict[str, Any][source]
使用指定的索引名称创建索引

实例构造

参数
  • dimensions (int) – 向量相似度的维度数量。支持的最大维度数为 2000

  • similarity (DocumentDBSimilarityType) –

    用于 HNSW 索引的相似度算法。可能的选项包括

    • DocumentDBSimilarityType.COS (余弦距离),

    • DocumentDBSimilarityType.EUC (欧几里得距离), 和

    • DocumentDBSimilarityType.DOT (点积)。

  • m (int) – 指定 HNSW 索引的最大连接数。对内存消耗有很大影响。

  • ef_construction (int) – 指定用于构建 HNSW 索引图的动态候选列表的大小。值越高,结果越准确,但索引速度越慢。

返回

描述已创建索引的对象

返回类型

dict[str, Any]

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

通过向量 ID 或其他标准删除。

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

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

返回

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

返回类型

Optional[bool]

delete_document_by_id(document_id: Optional[str] = None) None[source]

通过 ID 删除特定文档

参数

document_id (Optional[str]) – 文档标识符

返回类型

None

delete_index() None[source]

如果实例构造期间指定的索引存在,则删除该索引

返回类型

None

classmethod from_connection_string(connection_string: str, namespace: str, embedding: Embeddings, **kwargs: Any) DocumentDBVectorSearch[source]

从连接字符串创建 DocumentDBVectorSearch 实例

参数
  • connection_string (str) – DocumentDB 集群端点连接字符串

  • namespace (str) – 命名空间 (database.collection)

  • embedding (Embeddings) – 向量嵌入实用程序

  • **kwargs (Any) – 动态关键字参数

返回

向量存储的实例

返回类型

DocumentDBVectorSearch

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

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

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

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

  • kwargs (Any) – 附加关键字参数。

返回

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

返回类型

VectorStore

classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, collection: Optional[Collection[DocumentDBDocumentType]] = None, **kwargs: Any) DocumentDBVectorSearch[source]

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

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

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

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

  • kwargs (Any) – 附加关键字参数。

  • collection (Optional[Collection[DocumentDBDocumentType]]) –

返回

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

返回类型

VectorStore

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

通过 ID 获取文档。

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

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

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

如果某些 ID 没有找到文档,则此方法不应引发异常。

参数

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

返回

文档列表。

返回类型

List[Document]

0.2.11 版本新增。

get_index_name() str[source]

返回索引名称

返回

返回索引名称

返回类型

str

index_exists() bool[source]
验证实例构造期间指定的索引名称是否存在

集合上是否存在构造

返回

成功返回 True,如果集合上不存在此类索引则返回 False

on the collection

返回类型

bool

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

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

参数
  • query (str) – 要查找与其相似文档的文本。

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

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

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

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

返回

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

返回类型

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) – 传递给搜索方法的参数。

返回

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

返回类型

List[Document]

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

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

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

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

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

返回

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

引发

ValueError – 如果 search_type 不是 “similarity”、“mmr” 或 “similarity_score_threshold” 之一。

返回类型

List[Document]

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

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

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

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

  • ef_search (int) –

  • filter (Optional[Dict[str, Any]]) –

  • **kwargs

返回

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

返回类型

List[Document]

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

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

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

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

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

返回

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

返回类型

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 之间的浮点值,用于

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

返回

(文档,相似度分数)元组列表。

返回类型

List[Tuple[Document, float]]

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

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

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

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

返回

(文档,相似度分数)元组列表。

返回类型

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 不应包含 ids 以避免语义模糊。相反,ID 应该作为 Document 对象的一部分提供。

Yields

UpsertResponse – 响应对象,其中包含向量存储中成功添加或更新的 ID 列表以及添加或更新失败的 ID 列表。

返回类型

Iterator[UpsertResponse]

0.2.11 版本新增。

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

Beta 版本

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

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

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

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

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

  • kwargs (Any) – 附加关键字参数。

返回

响应对象,其中包含向量存储中成功添加或更新的 ID 列表以及添加或更新失败的 ID 列表。

返回类型

UpsertResponse

0.2.11 版本新增。