langchain_community.vectorstores.manticore_search
.ManticoreSearch¶
- class langchain_community.vectorstores.manticore_search.ManticoreSearch(embedding: Embeddings, *, config: Optional[ManticoreSearchSettings] = None, **kwargs: Any)[source]¶
ManticoreSearch 引擎 向量存储。
要使用,您应该安装
manticoresearch
python 包。示例 (Example)
from langchain_community.vectorstores import Manticore from langchain_community.embeddings.openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings() vectorstore = ManticoreSearch(embeddings)
ManticoreSearch 包装器到 LangChain (ManticoreSearch Wrapper to LangChain)
- 参数 (Parameters)
embedding (Embeddings) – 文本嵌入模型 (Text embedding model)。
config (ManticoreSearchSettings) – ManticoreSearch 客户端的配置 (Configuration of ManticoreSearch Client)
**kwargs – 其他关键字参数将传递到 API 客户端 manticoresearch-python 的配置中。有关更多信息,请参阅 https://github.com/manticoresoftware/manticoresearch-python。
属性 (Attributes)
embeddings
如果可用,访问查询嵌入对象 (Access the query embedding object if available)。
metadata_column
方法 (Methods)
__init__
(embedding, *[, config])ManticoreSearch 包装器到 LangChain (ManticoreSearch Wrapper to LangChain)
aadd_documents
(documents, **kwargs)异步地通过嵌入运行更多文档并添加到向量存储 (Async run more documents through the embeddings and add to the vectorstore)。
aadd_texts
(texts[, metadatas])异步地通过嵌入运行更多文本并添加到向量存储 (Async run more texts through the embeddings and add to the vectorstore)。
add_documents
(documents, **kwargs)在向量存储中添加或更新文档 (Add or update documents in the vectorstore)。
add_texts
(texts[, metadatas, batch_size, ...])通过嵌入插入更多文本并添加到 VectorStore (Insert more texts through the embeddings and add to the VectorStore)。
adelete
([ids])异步地按向量 ID 或其他条件删除 (Async delete by vector ID or other criteria)。
afrom_documents
(documents, embedding, **kwargs)异步地从文档和嵌入初始化并返回 VectorStore (Async return VectorStore initialized from documents and embeddings)。
afrom_texts
(texts, embedding[, metadatas])异步地从文本和嵌入初始化并返回 VectorStore (Async return VectorStore initialized from texts and embeddings)。
aget_by_ids
(ids, /)异步地通过 ID 获取文档 (Async get documents by their IDs)。
amax_marginal_relevance_search
(query[, k, ...])异步地返回使用最大边际相关性选择的文档 (Async return docs selected using the maximal marginal relevance)。
异步地返回使用最大边际相关性选择的文档 (Async return docs selected using the maximal marginal relevance)。
as_retriever
(**kwargs)从这个 VectorStore 初始化并返回 VectorStoreRetriever (Return VectorStoreRetriever initialized from this VectorStore)。
asearch
(query, search_type, **kwargs)异步地返回使用指定搜索类型与查询最相似的文档 (Async return docs most similar to query using a specified search type)。
asimilarity_search
(query[, k])异步地返回与查询最相似的文档 (Async return docs most similar to query)。
asimilarity_search_by_vector
(embedding[, k])异步地返回与嵌入向量最相似的文档 (Async return docs most similar to embedding vector)。
异步地返回范围在 [0, 1] 内的文档和相关性得分 (Async return docs and relevance scores in the range [0, 1])。
asimilarity_search_with_score
(*args, **kwargs)异步地运行带距离的相似性搜索 (Async run similarity search with distance)。
astreaming_upsert
(items, /, batch_size, **kwargs)aupsert
(items, /, **kwargs)delete
([ids])按向量 ID 或其他条件删除 (Delete by vector ID or other criteria)。
drop
()辅助函数:删除数据 (Helper function: Drop data)
from_documents
(documents, embedding, *[, ...])从文档和嵌入初始化并返回 VectorStore (Return VectorStore initialized from documents and embeddings)。
from_texts
(texts, embedding[, metadatas, ...])从文本和嵌入初始化并返回 VectorStore (Return VectorStore initialized from texts and embeddings)。
get_by_ids
(ids, /)通过 ID 获取文档 (Get documents by their IDs)。
max_marginal_relevance_search
(query[, k, ...])返回使用最大边际相关性选择的文档 (Return docs selected using the maximal marginal relevance)。
返回使用最大边际相关性选择的文档 (Return docs selected using the maximal marginal relevance)。
search
(query, search_type, **kwargs)返回使用指定搜索类型与查询最相似的文档 (Return docs most similar to query using a specified search type)。
similarity_search
(query[, k])使用 ManticoreSearch 执行相似性搜索 (Perform a similarity search with ManticoreSearch)
similarity_search_by_vector
(embedding[, k])通过向量使用 ManticoreSearch 执行相似性搜索 (Perform a similarity search with ManticoreSearch by vectors)
返回范围在 [0, 1] 内的文档和相关性得分 (Return docs and relevance scores in the range [0, 1])。
similarity_search_with_score
(*args, **kwargs)运行带距离的相似性搜索 (Run similarity search with distance)。
streaming_upsert
(items, /, batch_size, **kwargs)upsert
(items, /, **kwargs)- __init__(embedding: Embeddings, *, config: Optional[ManticoreSearchSettings] = None, **kwargs: Any) None [source]¶
ManticoreSearch 包装器到 LangChain (ManticoreSearch Wrapper to LangChain)
- 参数 (Parameters)
embedding (Embeddings) – 文本嵌入模型 (Text embedding model)。
config (ManticoreSearchSettings) – ManticoreSearch 客户端的配置 (Configuration of ManticoreSearch Client)
**kwargs – 其他关键字参数将传递到 API 客户端 manticoresearch-python 的配置中。有关更多信息,请参阅 https://github.com/manticoresoftware/manticoresearch-python。
- 返回类型 (Return type)
None
- async aadd_documents(documents: List[Document], **kwargs: Any) List[str] ¶
异步地通过嵌入运行更多文档并添加到向量存储 (Async run more documents through the embeddings and add to the vectorstore)。
- 参数 (Parameters)
documents (List[Document]) – 要添加到向量存储的文档列表 (Documents to add to the vectorstore)。
kwargs (Any) – 额外的关键字参数 (Additional keyword arguments)。
- 返回值 (Returns)
添加的文本的 ID 列表 (List of IDs of the added texts)。
- Raises
ValueError – 如果 ID 数量与文档数量不匹配 (If the number of IDs does not match the number of documents)。
- 返回类型 (Return type)
List[str]
- async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) List[str] ¶
异步地通过嵌入运行更多文本并添加到向量存储 (Async 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)。默认为 None。
**kwargs (Any) – 向量存储特定的参数 (vectorstore specific parameters)。
- 返回值 (Returns)
从将文本添加到向量存储中获得的 ID 列表 (List of ids from adding the texts into the vectorstore)。
- Raises
ValueError – 如果元数据的数量与文本的数量不匹配 (If the number of metadatas does not match the number of texts)。
ValueError – 如果 ID 的数量与文本的数量不匹配 (If the number of ids does not match the number of texts)。
- 返回类型 (Return type)
List[str]
- add_documents(documents: List[Document], **kwargs: Any) List[str] ¶
在向量存储中添加或更新文档 (Add or update documents in the vectorstore)。
- 参数 (Parameters)
documents (List[Document]) – 要添加到向量存储的文档列表 (Documents to add to the vectorstore)。
kwargs (Any) – 额外的关键字参数 (Additional keyword arguments)。如果 kwargs 包含 ids 并且 documents 包含 ids,则 kwargs 中的 ids 将优先 (if kwargs contains ids and documents contain ids, the ids in the kwargs will receive precedence)。
- 返回值 (Returns)
添加的文本的 ID 列表 (List of IDs of the added texts)。
- Raises
ValueError – 如果 ID 的数量与文档的数量不匹配 (If the number of ids does not match the number of documents)。
- 返回类型 (Return type)
List[str]
- add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, *, batch_size: int = 32, text_ids: Optional[List[str]] = None, **kwargs: Any) List[str] [source]¶
通过嵌入插入更多文本并添加到 VectorStore (Insert more texts through the embeddings and add to the VectorStore)。
- 参数 (Parameters)
texts (Iterable[str]) – 要添加到 VectorStore 的字符串可迭代对象 (Iterable of strings to add to the VectorStore)
metadata – 要插入的可选列数据 (Optional column data to be inserted)
batch_size (int) – 插入的批次大小 (Batch size of insertion)
ids – 与文本关联的可选 ID 列表 (Optional list of ids to associate with the texts)
metadatas (Optional[List[dict]]) –
text_ids (Optional[List[str]]) –
kwargs (Any) –
- 返回值 (Returns)
从将文本添加到 VectorStore 中获得的 ID 列表 (List of ids from adding the texts into the VectorStore)。
- 返回类型 (Return type)
List[str]
- async adelete(ids: Optional[List[str]] = None, **kwargs: Any) Optional[bool] ¶
异步地按向量 ID 或其他条件删除 (Async delete by vector ID or other criteria)。
- 参数 (Parameters)
ids (Optional[List[str]]) – 要删除的 ID 列表 (List of ids to delete)。如果为 None,则删除全部 (If None, delete all)。默认为 None。
**kwargs (Any) – 子类可能使用的其他关键字参数 (Other keyword arguments that subclasses might use)。
- 返回值 (Returns)
如果删除成功,则为 True,否则为 False,如果未实现则为 None (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 ¶
异步地从文档和嵌入初始化并返回 VectorStore (Async 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) – 额外的关键字参数 (Additional keyword arguments)。
- 返回值 (Returns)
从文档和嵌入初始化的 VectorStore (VectorStore initialized from documents and embeddings)。
- 返回类型 (Return type)
- async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) VST ¶
异步地从文本和嵌入初始化并返回 VectorStore (Async return VectorStore initialized from texts and embeddings)。
- 参数 (Parameters)
texts (List[str]) – 要添加到向量存储的文本列表 (Texts to add to the vectorstore)。
embedding (Embeddings) – 要使用的嵌入函数 (Embedding function to use)。
metadatas (Optional[List[dict]]) – 与文本关联的可选元数据列表 (Optional list of metadatas associated with the texts)。默认为 None。
kwargs (Any) – 额外的关键字参数 (Additional keyword arguments)。
- 返回值 (Returns)
从文本和嵌入初始化的 VectorStore (VectorStore initialized from texts and embeddings)。
- 返回类型 (Return type)
- async aget_by_ids(ids: Sequence[str], /) List[Document] ¶
异步地通过 ID 获取文档 (Async get documents by their IDs)。
返回的文档应将 ID 字段设置为向量存储中文档的 ID (The returned documents are expected to have the ID field set to the ID of the document in the vector store)。
如果某些 ID 未找到或存在重复的 ID,则返回的文档可能少于请求的文档 (Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs)。
用户不应假定返回文档的顺序与输入 ID 的顺序匹配 (Users should not assume that the order of the returned documents matches the order of the input IDs)。相反,用户应依赖返回文档的 ID 字段 (Instead, users should rely on the ID field of the returned documents)。
如果某些 ID 未找到文档,则此方法不应引发异常 (This method should NOT raise exceptions if no documents are found for some IDs)。
- 参数 (Parameters)
ids (Sequence[str]) – 要检索的 ID 列表 (List of ids to retrieve)。
- 返回值 (Returns)
文档列表 (List of Documents)。
- 返回类型 (Return type)
List[Document]
0.2.11 版本新增 (New in version 0.2.11)。
- async amax_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) List[Document] ¶
异步地返回使用最大边际相关性选择的文档 (Async return docs selected using the maximal marginal relevance)。
最大边际相关性在查询相似性和所选文档之间的多样性之间进行优化。
- 参数 (Parameters)
query (str) – 用于查找相似文档的文本。
k (int) – 返回的文档数量。默认为 4。
fetch_k (int) – 用于获取并传递给 MMR 算法的文档数量。默认为 20。
lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。
kwargs (Any) –
- 返回值 (Returns)
由最大边际相关性选择的文档列表。
- 返回类型 (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] ¶
异步地返回使用最大边际相关性选择的文档 (Async return docs selected using the maximal marginal relevance)。
最大边际相关性在查询相似性和所选文档之间的多样性之间进行优化。
- 参数 (Parameters)
embedding (List[float]) – 用于查找相似文档的嵌入向量。
k (int) – 返回的文档数量。默认为 4。
fetch_k (int) – 用于获取并传递给 MMR 算法的文档数量。默认为 20。
lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。
**kwargs (Any) – 传递给搜索方法的参数。
- 返回值 (Returns)
由最大边际相关性选择的文档列表。
- 返回类型 (Return type)
List[Document]
- as_retriever(**kwargs: Any) VectorStoreRetriever ¶
从这个 VectorStore 初始化并返回 VectorStoreRetriever (Return VectorStoreRetriever initialized from this VectorStore)。
- 参数 (Parameters)
**kwargs (Any) –
传递给搜索函数的关键字参数。可以包括: search_type (Optional[str]): 定义 Retriever 应执行的搜索类型。可以是 “similarity”(默认)、“mmr” 或 “similarity_score_threshold”。
Retriever 应执行的搜索类型。可以是 “similarity”(默认)、“mmr” 或 “similarity_score_threshold”。
- search_kwargs (Optional[Dict]): 传递给搜索函数的关键字参数。可以包括如下内容:
- search_kwargs (Optional[Dict]): 传递给搜索函数的关键字参数。可以包括如下内容:
k: 返回的文档数量(默认值:4) score_threshold: 相似度分数阈值的最小相关性阈值
用于 similarity_score_threshold
- fetch_k: 传递给 MMR 算法的文档数量
(默认值:20)
- lambda_mult: MMR 返回结果的多样性;
1 表示最小多样性,0 表示最大多样性。(默认值:0.5)
filter: 按文档元数据过滤
- 返回值 (Returns)
VectorStore 的 Retriever 类。
- 返回类型 (Return type)
示例
# 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] ¶
异步地返回使用指定搜索类型与查询最相似的文档 (Async return docs most similar to query using a specified search type)。
- 参数 (Parameters)
query (str) – 输入文本。
search_type (str) – 要执行的搜索类型。可以是 “similarity”、“mmr” 或 “similarity_score_threshold”。
**kwargs (Any) – 传递给搜索方法的参数。
- 返回值 (Returns)
与查询最相似的文档列表。
- Raises
ValueError – 如果 search_type 不是 “similarity”、“mmr” 或 “similarity_score_threshold” 之一。
- 返回类型 (Return type)
List[Document]
- async asimilarity_search(query: str, k: int = 4, **kwargs: Any) List[Document] ¶
异步地返回与查询最相似的文档 (Async return docs most similar to query)。
- 参数 (Parameters)
query (str) – 输入文本。
k (int) – 返回的文档数量。默认为 4。
**kwargs (Any) – 传递给搜索方法的参数。
- 返回值 (Returns)
与查询最相似的文档列表。
- 返回类型 (Return type)
List[Document]
- async asimilarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) List[Document] ¶
异步地返回与嵌入向量最相似的文档 (Async return docs most similar to embedding vector)。
- 参数 (Parameters)
embedding (List[float]) – 用于查找相似文档的嵌入向量。
k (int) – 返回的文档数量。默认为 4。
**kwargs (Any) – 传递给搜索方法的参数。
- 返回值 (Returns)
与查询向量最相似的文档列表。
- 返回类型 (Return type)
List[Document]
- async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) List[Tuple[Document, float]] ¶
异步地返回范围在 [0, 1] 内的文档和相关性得分 (Async return docs and relevance scores in the range [0, 1])。
0 表示不相似,1 表示最相似。
- 参数 (Parameters)
query (str) – 输入文本。
k (int) – 返回的文档数量。默认为 4。
**kwargs (Any) –
传递给相似度搜索的 kwargs。应包括: score_threshold: 可选,介于 0 到 1 之间的浮点值,用于
过滤检索到的文档结果集
- 返回值 (Returns)
(文档,相似度分数)元组列表
- 返回类型 (Return type)
List[Tuple[Document, float]]
- async asimilarity_search_with_score(*args: Any, **kwargs: Any) List[Tuple[Document, float]] ¶
异步地运行带距离的相似性搜索 (Async run similarity search with distance)。
- 参数 (Parameters)
*args (Any) – 传递给搜索方法的参数。
**kwargs (Any) – 传递给搜索方法的参数。
- 返回值 (Returns)
(文档,相似度分数)元组列表。
- 返回类型 (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 的异步版本。
- 参数 (Parameters)
items (AsyncIterable[Document]) – 要添加到向量存储的文档的可迭代对象。
batch_size (int) – 每次批量更新的大小。
kwargs (Any) – 附加关键字参数。 kwargs 应仅包含所有文档通用的参数。(例如,索引超时、重试策略等)kwargs 不应包含 id,以避免语义不明确。ID 应作为 Document 对象的一部分提供。
- Yields
UpsertResponse – 响应对象,其中包含已成功添加到向量存储或在向量存储中更新的 ID 列表,以及未能添加或更新的 ID 列表。
- 返回类型 (Return type)
AsyncIterator[UpsertResponse]
0.2.11 版本新增 (New in version 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 方法应将文档添加到向量存储中。
- 参数 (Parameters)
items (Sequence[Document]) – 要添加到向量存储的文档序列。
kwargs (Any) – 额外的关键字参数 (Additional keyword arguments)。
- 返回值 (Returns)
响应对象,其中包含已成功添加到向量存储或在向量存储中更新的 ID 列表,以及未能添加或更新的 ID 列表。
- 返回类型 (Return type)
0.2.11 版本新增 (New in version 0.2.11)。
- delete(ids: Optional[List[str]] = None, **kwargs: Any) Optional[bool] ¶
按向量 ID 或其他条件删除 (Delete by vector ID or other criteria)。
- 参数 (Parameters)
ids (Optional[List[str]]) – 要删除的 ID 列表 (List of ids to delete)。如果为 None,则删除全部 (If None, delete all)。默认为 None。
**kwargs (Any) – 子类可能使用的其他关键字参数 (Other keyword arguments that subclasses might use)。
- 返回值 (Returns)
如果删除成功,则为 True,否则为 False,如果未实现则为 None (True if deletion is successful, False otherwise, None if not implemented)。
- 返回类型 (Return type)
Optional[bool]
- classmethod from_documents(documents: List[Document], embedding: Embeddings, *, config: Optional[ManticoreSearchSettings] = None, text_ids: Optional[List[str]] = None, batch_size: int = 32, **kwargs: Any) ManticoreSearch [source]¶
从文档和嵌入初始化并返回 VectorStore (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) – 额外的关键字参数 (Additional keyword arguments)。
config (Optional[ManticoreSearchSettings]) –
text_ids (Optional[List[str]]) –
batch_size (int) –
- 返回值 (Returns)
从文档和嵌入初始化的 VectorStore (VectorStore initialized from documents and embeddings)。
- 返回类型 (Return type)
- classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[Dict[Any, Any]]] = None, *, config: Optional[ManticoreSearchSettings] = None, text_ids: Optional[List[str]] = None, batch_size: int = 32, **kwargs: Any) ManticoreSearch [source]¶
从文本和嵌入初始化并返回 VectorStore (Return VectorStore initialized from texts and embeddings)。
- 参数 (Parameters)
texts (List[str]) – 要添加到向量存储的文本列表 (Texts to add to the vectorstore)。
embedding (Embeddings) – 要使用的嵌入函数 (Embedding function to use)。
metadatas (Optional[List[Dict[Any, Any]]]) – 与文本关联的可选元数据列表。默认为 None。
kwargs (Any) – 额外的关键字参数 (Additional keyword arguments)。
config (Optional[ManticoreSearchSettings]) –
text_ids (Optional[List[str]]) –
batch_size (int) –
- 返回值 (Returns)
从文本和嵌入初始化的 VectorStore (VectorStore initialized from texts and embeddings)。
- 返回类型 (Return type)
- get_by_ids(ids: Sequence[str], /) List[Document] ¶
通过 ID 获取文档 (Get documents by their IDs)。
返回的文档应将 ID 字段设置为向量存储中文档的 ID (The returned documents are expected to have the ID field set to the ID of the document in the vector store)。
如果某些 ID 未找到或存在重复的 ID,则返回的文档可能少于请求的文档 (Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs)。
用户不应假定返回文档的顺序与输入 ID 的顺序匹配 (Users should not assume that the order of the returned documents matches the order of the input IDs)。相反,用户应依赖返回文档的 ID 字段 (Instead, users should rely on the ID field of the returned documents)。
如果某些 ID 未找到文档,则此方法不应引发异常 (This method should NOT raise exceptions if no documents are found for some IDs)。
- 参数 (Parameters)
ids (Sequence[str]) – 要检索的 ID 列表 (List of ids to retrieve)。
- 返回值 (Returns)
文档列表 (List of Documents)。
- 返回类型 (Return type)
List[Document]
0.2.11 版本新增 (New in version 0.2.11)。
- 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)。
最大边际相关性在查询相似性和所选文档之间的多样性之间进行优化。
- 参数 (Parameters)
query (str) – 用于查找相似文档的文本。
k (int) – 返回的文档数量。默认为 4。
fetch_k (int) – 用于获取并传递给 MMR 算法的文档数量。默认为 20。
lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。
**kwargs (Any) – 传递给搜索方法的参数。
- 返回值 (Returns)
由最大边际相关性选择的文档列表。
- 返回类型 (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)。
最大边际相关性在查询相似性和所选文档之间的多样性之间进行优化。
- 参数 (Parameters)
embedding (List[float]) – 用于查找相似文档的嵌入向量。
k (int) – 返回的文档数量。默认为 4。
fetch_k (int) – 用于获取并传递给 MMR 算法的文档数量。默认为 20。
lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。
**kwargs (Any) – 传递给搜索方法的参数。
- 返回值 (Returns)
由最大边际相关性选择的文档列表。
- 返回类型 (Return type)
List[Document]
- search(query: str, search_type: str, **kwargs: Any) List[Document] ¶
返回使用指定搜索类型与查询最相似的文档 (Return docs most similar to query using a specified search type)。
- 参数 (Parameters)
query (str) – 输入文本
search_type (str) – 要执行的搜索类型。可以是 “similarity”、“mmr” 或 “similarity_score_threshold”。
**kwargs (Any) – 传递给搜索方法的参数。
- 返回值 (Returns)
与查询最相似的文档列表。
- Raises
ValueError – 如果 search_type 不是 “similarity”、“mmr” 或 “similarity_score_threshold” 之一。
- 返回类型 (Return type)
List[Document]
- similarity_search(query: str, k: int = 4, **kwargs: Any) List[Document] [source]¶
使用 ManticoreSearch 执行相似性搜索 (Perform a similarity search with ManticoreSearch)
- 参数 (Parameters)
query (str) – 查询字符串
k (int, optional) – 要检索的 Top K 邻居。默认为 4。
kwargs (Any) –
- 返回值 (Returns)
文档列表
- 返回类型 (Return type)
List[Document]
- similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) List[Document] [source]¶
通过向量使用 ManticoreSearch 执行相似性搜索 (Perform a similarity search with ManticoreSearch by vectors)
- 参数 (Parameters)
embedding (List[float]) – 嵌入向量
k (int, optional) – 要检索的 Top K 邻居。默认为 4。
kwargs (Any) –
- 返回值 (Returns)
文档列表
- 返回类型 (Return type)
List[Document]
- similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) List[Tuple[Document, float]] ¶
返回范围在 [0, 1] 内的文档和相关性得分 (Return docs and relevance scores in the range [0, 1])。
0 表示不相似,1 表示最相似。
- 参数 (Parameters)
query (str) – 输入文本。
k (int) – 返回的文档数量。默认为 4。
**kwargs (Any) –
传递给相似度搜索的 kwargs。应包括: score_threshold: 可选,介于 0 到 1 之间的浮点值,用于
过滤检索到的文档结果集。
- 返回值 (Returns)
(文档,相似度分数)元组列表。
- 返回类型 (Return type)
List[Tuple[Document, float]]
- similarity_search_with_score(*args: Any, **kwargs: Any) List[Tuple[Document, float]] ¶
运行带距离的相似性搜索 (Run similarity search with distance)。
- 参数 (Parameters)
*args (Any) – 传递给搜索方法的参数。
**kwargs (Any) – 传递给搜索方法的参数。
- 返回值 (Returns)
(文档,相似度分数)元组列表。
- 返回类型 (Return type)
List[Tuple[Document, float]]
- streaming_upsert(items: Iterable[Document], /, batch_size: int, **kwargs: Any) Iterator[UpsertResponse] ¶
Beta 版本
在 0.2.11 版本中添加。API 可能会发生更改。
以流式方式更新插入文档。
- 参数 (Parameters)
items (Iterable[Document]) – 要添加到向量存储的可迭代文档集合。
batch_size (int) – 每次批量更新的大小。
kwargs (Any) – 额外的关键字参数。 kwargs 应该只包含所有文档通用的参数。(例如,索引超时、重试策略等。)kwargs 不应包含 ids,以避免语义模糊。相反,ID 应该作为 Document 对象的一部分提供。
- Yields
UpsertResponse – 响应对象,其中包含已成功添加到向量存储或在向量存储中更新的 ID 列表,以及未能添加或更新的 ID 列表。
- 返回类型 (Return type)
Iterator[UpsertResponse]
0.2.11 版本新增 (New in version 0.2.11)。
- upsert(items: Sequence[Document], /, **kwargs: Any) UpsertResponse ¶
Beta 版本
在 0.2.11 版本中添加。API 可能会发生更改。
在向量存储中添加或更新文档 (Add or update documents in the vectorstore)。
如果提供了 Document 对象的 ID 字段,则 upsert 功能应使用该字段。如果未提供 ID,则 upsert 方法可以自由地为文档生成 ID。
当指定了 ID 且文档已存在于向量存储中时,upsert 方法应使用新数据更新文档。如果文档不存在,则 upsert 方法应将文档添加到向量存储中。
- 参数 (Parameters)
items (Sequence[Document]) – 要添加到向量存储的文档序列。
kwargs (Any) – 额外的关键字参数 (Additional keyword arguments)。
- 返回值 (Returns)
响应对象,其中包含已成功添加到向量存储或在向量存储中更新的 ID 列表,以及未能添加或更新的 ID 列表。
- 返回类型 (Return type)
0.2.11 版本新增 (New in version 0.2.11)。