langchain_community.vectorstores.vdms
.VDMS¶
- class langchain_community.vectorstores.vdms.VDMS(client: vdms.vdms, *, embedding: Optional[Embeddings] = None, collection_name: str = 'langchain', distance_strategy: DISTANCE_METRICS = 'L2', engine: ENGINES = 'FaissFlat', relevance_score_fn: Optional[Callable[[float], float]] = None, embedding_dimensions: Optional[int] = None)[source]¶
Intel Lab’s VDMS for vector-store workloads.
To use, you should have both: - the
vdms
python package installed - a host (str) and port (int) associated with a deployed VDMS ServerVisit https://github.com/IntelLabs/vdms/wiki more information.
IT IS HIGHLY SUGGESTED TO NORMALIZE YOUR DATA.
- Parameters
client (vdms.vdms) – VDMS Client used to connect to VDMS server
collection_name (str) – Name of data collection [Default: langchain]
distance_strategy (DISTANCE_METRICS) – Method used to calculate distances. VDMS supports “L2” (euclidean distance) or “IP” (inner product) [Default: L2]
engine (ENGINES) – Underlying implementation for indexing and computing distances. VDMS supports TileDBDense, TileDBSparse, FaissFlat, FaissIVFFlat, and Flinng [Default: FaissFlat]
embedding (Optional[Embeddings]) – Any embedding function implementing langchain_core.embeddings.Embeddings interface.
relevance_score_fn (Optional[Callable[[float], float]]) – Function for obtaining relevance score
embedding_dimensions (Optional[int]) –
Example
from langchain_huggingface import HuggingFaceEmbeddings from langchain_community.vectorstores.vdms import VDMS, VDMS_Client vectorstore = VDMS( client=VDMS_Client("localhost", 55555), embedding=HuggingFaceEmbeddings(), collection_name="langchain-demo", distance_strategy="L2", engine="FaissFlat", )
Attributes
embeddings
Access the query embedding object if available.
Methods
__init__
(client, *[, embedding, ...])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
(collection_name, texts, embeddings[, ...])add_documents
(documents, **kwargs)Add or update documents in the vectorstore.
add_from
(texts, embeddings, ids[, ...])add_images
(uris[, metadatas, ids, ...])Run more images through the embeddings and add to the vectorstore.
add_set
(collection_name[, engine, metric])add_texts
(texts[, metadatas, ids, batch_size])Run more texts through the embeddings and add to the vectorstore.
add_videos
(paths[, texts, metadatas, ids, ...])Run videos through the embeddings and add to the vectorstore.
adelete
([ids])Async delete by vector ID or other criteria.
afrom_documents
(documents, embedding, **kwargs)Async return VectorStore initialized from documents and embeddings.
afrom_texts
(texts, embedding[, metadatas])Async return VectorStore initialized from texts and embeddings.
aget_by_ids
(ids, /)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)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.
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)count
(collection_name)decode_image
(base64_image)delete
([ids, collection_name, constraints])Delete by ID.
encode_image
(image_path)from_documents
(documents[, embedding, ids, ...])Create a VDMS vectorstore from a list of documents.
from_texts
(texts[, embedding, metadatas, ...])Create a VDMS vectorstore from a raw documents.
get
(collection_name[, constraints, limit, ...])Gets the collection.
get_by_ids
(ids, /)Get documents by their IDs.
get_descriptor_response
(command_str, setname)get_k_candidates
(setname, fetch_k[, ...])max_marginal_relevance_search
(query[, k, ...])Return docs selected using the maximal marginal relevance.
Return docs selected using the maximal marginal relevance.
Return docs selected using the maximal marginal relevance.
Return docs selected using the maximal marginal relevance.
query_collection_embeddings
([...])search
(query, search_type, **kwargs)Return docs most similar to query using a specified search type.
similarity_search
(query[, k, fetch_k, filter])Run similarity search with VDMS.
similarity_search_by_vector
(embedding[, k, ...])Return docs most similar to embedding vector.
Return docs and relevance scores in the range [0, 1].
similarity_search_with_score
(query[, k, ...])Run similarity search with VDMS with distance.
similarity_search_with_score_by_vector
(embedding)Return docs most similar to embedding vector and similarity score.
streaming_upsert
(items, /, batch_size, **kwargs)update_document
(collection_name, ...)Update a document in the collection.
update_documents
(collection_name, ids, documents)Update a document in the collection.
upsert
(items, /, **kwargs)- __init__(client: vdms.vdms, *, embedding: Optional[Embeddings] = None, collection_name: str = 'langchain', distance_strategy: DISTANCE_METRICS = 'L2', engine: ENGINES = 'FaissFlat', relevance_score_fn: Optional[Callable[[float], float]] = None, embedding_dimensions: Optional[int] = None) None [source]¶
- Parameters
client (vdms.vdms) –
embedding (Optional[Embeddings]) –
collection_name (str) –
distance_strategy (DISTANCE_METRICS) –
engine (ENGINES) –
relevance_score_fn (Optional[Callable[[float], float]]) –
embedding_dimensions (Optional[int]) –
- 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
List of IDs of the added texts.
- Raises
ValueError – 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. Default is None.
**kwargs (Any) – vectorstore specific parameters.
- Returns
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 – If the number of ids does not match the number of texts.
- Return type
List[str]
- add(collection_name: str, texts: List[str], embeddings: List[List[float]], metadatas]: Optional[Union[List[None], List[Dict[str, Any]]]] = None, ids]: Optional[List[str]] = None) List [source]¶
- Parameters
collection_name (str) –
texts (List[str]) –
embeddings (List[List[float]]) –
metadatas (Optional[Union[List[None], List[Dict[str, Any]]]]) –
ids (Optional[List[str]]) –
- Return type
List
- 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. if kwargs contains ids and documents contain ids, the ids in the kwargs will receive precedence.
- Returns
List of IDs of the added texts.
- Raises
ValueError – If the number of ids does not match the number of documents.
- Return type
List[str]
- add_from(texts]: List[str], embeddings]: List[List[float]], ids]: List[str], metadatas]: Optional[List[dict]] = None, batch_size]: int = 32, **kwargs]: Any) List[str] [source]¶
- Parameters
texts (List[str]) –
embeddings (List[List[float]]) –
ids (List[str]) –
metadatas (Optional[List[dict]]) –
batch_size (int) –
kwargs (Any) –
- Return type
List[str]
- add_images(uris]: List[str], metadatas]: Optional[List[dict]] = None, ids]: Optional[List[str]] = None, batch_size]: int = 32, add_path]: Optional[bool] = True, **kwargs]: Any) List[str] [source]¶
Run more images through the embeddings and add to the vectorstore.
图像作为嵌入(AddDescriptor)添加到 VDMS 中,而不是作为单独的实体(AddImage),以利用相似性搜索功能
- Parameters
uris (List[str]) – 要添加到向量存储的图像路径列表。
metadatas (Optional[List[dict]]) – 与图像关联的可选元数据列表。
ids (Optional[List[str]]) – 可选的唯一 ID 列表。
batch_size (int) – 发送到服务器的并发请求数。
add_path (Optional[bool]) – 布尔值,用于将图像路径添加为元数据
kwargs (Any) –
- Returns
将图像添加到向量存储后返回的 ID 列表。
- Return type
List[str]
- add_set(collection_name]: str, engine]: Literal['TileDBDense', 'TileDBSparse', 'FaissFlat', 'FaissIVFFlat', 'Flinng'] = 'FaissFlat', metric]: Literal['L2', 'IP'] = 'L2') str [source]¶
- Parameters
collection_name (str) –
engine (Literal['TileDBDense', 'TileDBSparse', 'FaissFlat', 'FaissIVFFlat', 'Flinng']) –
metric (Literal['L2', 'IP']) –
- Return type
str
- add_texts(texts]: Iterable[str], metadatas]: Optional[List[dict]] = None, ids]: Optional[List[str]] = None, batch_size]: int = 32, **kwargs]: Any) List[str] [source]¶
Run more texts through the embeddings and add to the vectorstore.
- Parameters
texts (Iterable[str]) – 要添加到向量存储的字符串列表。
metadatas (Optional[List[dict]]) – 与文本关联的可选元数据列表。
ids (Optional[List[str]]) – 可选的唯一 ID 列表。
batch_size (int) – 发送到服务器的并发请求数。
kwargs (Any) –
- Returns
List of ids from adding the texts into the vectorstore.
- Return type
List[str]
- add_videos(paths]: List[str], texts]: Optional[List[str]] = None, metadatas]: Optional[List[dict]] = None, ids]: Optional[List[str]] = None, batch_size]: int = 1, add_path]: Optional[bool] = True, **kwargs]: Any) List[str] [source]¶
Run videos through the embeddings and add to the vectorstore.
视频作为嵌入(AddDescriptor)添加到 VDMS 中,而不是作为单独的实体(AddVideo),以利用相似性搜索功能
- Parameters
paths (List[str]) – 要添加到向量存储的视频路径列表。
metadatas (Optional[List[dict]]) – 与视频关联的可选文本列表。
metadatas – 与视频关联的可选元数据列表。
ids (Optional[List[str]]) – 可选的唯一 ID 列表。
batch_size (int) – 发送到服务器的并发请求数。
add_path (Optional[bool]) – 布尔值,用于将视频路径添加为元数据
texts (Optional[List[str]]) –
kwargs (Any) –
- Returns
将视频添加到向量存储后返回的 ID 列表。
- Return type
List[str]
- async adelete(ids]: Optional[List[str]] = None, **kwargs]: Any) Optional[bool] ¶
Async delete by vector ID or other criteria.
- Parameters
ids (Optional[List[str]]) – 要删除的 ID 列表。如果为 None,则删除所有。默认为 None。
**kwargs (Any) – 子类可能使用的其他关键字参数。
- Returns
如果删除成功,则返回 True,否则返回 False,如果未实现则返回 None。
- Return type
Optional[bool]
- async classmethod afrom_documents(documents]: List[Document], embedding]: Embeddings, **kwargs]: Any) VST ¶
Async return VectorStore initialized from documents and embeddings.
- Parameters
documents (List[Document]) – 要添加到向量存储的文档列表。
embedding (Embeddings) – 要使用的嵌入函数。
kwargs (Any) – Additional keyword arguments.
- Returns
从文档和嵌入初始化的向量存储。
- Return type
- async classmethod afrom_texts(texts]: List[str], embedding]: Embeddings, metadatas]: Optional[List[dict]] = None, **kwargs]: Any) VST ¶
Async return VectorStore initialized from texts and embeddings.
- Parameters
texts (List[str]) – 要添加到向量存储的文本列表。
embedding (Embeddings) – 要使用的嵌入函数。
metadatas (Optional[List[dict]]) – Optional list of metadatas associated with the texts. Default is None.
kwargs (Any) – Additional keyword arguments.
- Returns
从文本和嵌入初始化的向量存储。
- Return type
- async aget_by_ids(ids]: Sequence[str], /) List[Document] ¶
Async get documents by their IDs.
返回的文档应将 ID 字段设置为向量存储中文档的 ID。
如果某些 ID 未找到或存在重复 ID,则返回的文档可能少于请求的文档数。
用户不应假设返回文档的顺序与输入 ID 的顺序匹配。相反,用户应依赖返回文档的 ID 字段。
如果某些 ID 没有找到文档,此方法**不应**引发异常。
- Parameters
ids (Sequence[str]) – 要检索的 ID 列表。
- Returns
文档列表。
- Return type
List[Document]
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 ¶
Return VectorStoreRetriever initialized from this VectorStore.
- Parameters
**kwargs (Any) –
传递给搜索函数的关键字参数。可以包括:search_type (Optional[str]): 定义检索器应执行的搜索类型。
可以是“similarity”(默认)、“mmr”或“similarity_score_threshold”。
- 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 的检索器类。
- 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]] ¶
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
元组列表,包含 (doc, similarity_score)
- 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
元组列表,包含 (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 的异步版本。
- Parameters
items (AsyncIterable[Document]) – 要添加到向量存储的文档的可迭代对象。
batch_size (int) – 每次更新批处理的大小。
kwargs (Any) – 额外的关键字参数。 kwargs 应仅包含所有文档通用的参数。(例如,索引超时、重试策略等)kwargs 不应包含 ids 以避免语义模糊。相反,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 的异步版本。
如果提供了 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 版本新增功能。
- delete(ids: Optional[List[str]] = None, collection_name: Optional[str] = None, constraints: Optional[Dict] = None, **kwargs: Any) bool [source]¶
按 ID 删除。这些是向量存储中的 ID。
- Parameters
ids (Optional[List[str]]) – 要删除的 ID 列表。
collection_name (Optional[str]) –
constraints (Optional[Dict]) –
kwargs (Any) –
- Returns
如果删除成功,则返回 True,否则返回 False,如果未实现则返回 None。
- Return type
Optional[bool]
- classmethod from_documents(documents: List[Document], embedding: Optional[Embeddings] = None, ids: Optional[List[str]] = None, batch_size: int = 32, collection_name: str = 'langchain', **kwargs: Any) VDMS [source]¶
Create a VDMS vectorstore from a list of documents.
- Parameters
collection_name (str) – 要创建的集合的名称。
documents (List[Document]) – 要添加到向量存储的文档列表。
embedding (Embeddings) – 嵌入函数。默认为 None。
ids (Optional[List[str]]) – 文档 ID 列表。默认为 None。
batch_size (int) – 发送到服务器的并发请求数。
kwargs (Any) –
- Returns
VDMS 向量存储。
- Return type
- classmethod from_texts(texts: List[str], embedding: Optional[Embeddings] = None, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, batch_size: int = 32, collection_name: str = 'langchain', **kwargs: Any) VDMS [source]¶
Create a VDMS vectorstore from a raw documents.
- Parameters
texts (List[str]) – 要添加到集合的文本列表。
embedding (Embeddings) – 嵌入函数。默认为 None。
metadatas (Optional[List[dict]]) – 元数据列表。默认为 None。
ids (Optional[List[str]]) – 文档 ID 列表。默认为 None。
batch_size (int) – 发送到服务器的并发请求数。
collection_name (str) – 要创建的集合的名称。
kwargs (Any) –
- Returns
VDMS 向量存储。
- Return type
- get(collection_name: str, constraints: Optional[Dict] = None, limit: Optional[int] = None, include: List[str] = ['metadata']) Tuple[Any, Any] [source]¶
获取集合。从数据存储中获取嵌入及其关联数据。如果未提供约束,则返回所有嵌入,最多为 limit 个。
- Parameters
constraints (Optional[Dict]) – 用于过滤结果的字典。例如 {“color” : [“==”, “red”], “price”: [“>”, 4.00]}。可选。
limit (Optional[int]) – 要返回的文档数量。可选。
include (List[str]) – 结果中要包含的内容列表。可以包含 “embeddings”, “metadatas”, “documents”。始终包含 Ids。默认为 [“metadatas”, “documents”]。可选。
collection_name (str) –
- Return type
Tuple[Any, Any]
- get_by_ids(ids: Sequence[str], /) List[Document] ¶
Get documents by their IDs.
返回的文档应将 ID 字段设置为向量存储中文档的 ID。
如果某些 ID 未找到或存在重复 ID,则返回的文档可能少于请求的文档数。
用户不应假设返回文档的顺序与输入 ID 的顺序匹配。相反,用户应依赖返回文档的 ID 字段。
如果某些 ID 没有找到文档,此方法**不应**引发异常。
- Parameters
ids (Sequence[str]) – 要检索的 ID 列表。
- Returns
文档列表。
- Return type
List[Document]
0.2.11 版本新增功能。
- get_descriptor_response(command_str: str, setname: str, k_neighbors: int = 3, fetch_k: int = 15, constraints: Optional[dict] = None, results: Optional[Dict[str, Any]] = None, query_embedding: Optional[List[float]] = None, normalize_distance: bool = False) Tuple[List[Dict[str, Any]], List] [source]¶
- Parameters
command_str (str) –
setname (str) –
k_neighbors (int) –
fetch_k (int) –
constraints (Optional[dict]) –
results (Optional[Dict[str, Any]]) –
query_embedding (Optional[List[float]]) –
normalize_distance (bool) –
- Return type
Tuple[List[Dict[str, Any]], List]
- get_k_candidates(setname: str, fetch_k: Optional[int], results: Optional[Dict[str, Any]] = None, all_blobs: Optional[List] = None, normalize: Optional[bool] = False) Tuple[List[Dict[str, Any]], List, float] [source]¶
- Parameters
setname (str) –
fetch_k (Optional[int]) –
results (Optional[Dict[str, Any]]) –
all_blobs (Optional[List]) –
normalize (Optional[bool]) –
- Return type
Tuple[List[Dict[str, Any]], List, float]
- max_marginal_relevance_search(query: str, k: int = 3, fetch_k: int = 15, lambda_mult: float = 0.5, filter: Optional[Dict[str, List]] = None, **kwargs: Any) List[Document] [source]¶
返回使用最大边际相关性选择的文档。最大边际相关性优化了与查询的相似性和所选文档之间的多样性。
- Parameters
query (str) – 要查找的查询。文本或图像或视频的路径。
k (int) – 要返回的文档数量。默认为 4。
fetch_k (int) – 要获取并传递给 MMR 算法的文档数量。
lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,其中 0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。
filter (Optional[Dict[str, str]]) – 按元数据过滤。默认为 None。
kwargs (Any) –
- Returns
由最大边际相关性选择的文档列表。
- Return type
List[Document]
- max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 3, fetch_k: int = 15, lambda_mult: float = 0.5, filter: Optional[Dict[str, List]] = None, **kwargs: Any) List[Document] [source]¶
返回使用最大边际相关性选择的文档。最大边际相关性优化了与查询的相似性和所选文档之间的多样性。
- Parameters
embedding (List[float]) – 用于查找相似文档的嵌入向量。
k (int) – 要返回的文档数量。默认为 4。
fetch_k (int) – 要获取并传递给 MMR 算法的文档数量。
lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,其中 0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。
filter (Optional[Dict[str, str]]) – 按元数据过滤。默认为 None。
kwargs (Any) –
- Returns
由最大边际相关性选择的文档列表。
- Return type
List[Document]
- max_marginal_relevance_search_with_score(query: str, k: int = 3, fetch_k: int = 15, lambda_mult: float = 0.5, filter: Optional[Dict[str, List]] = None, **kwargs: Any) List[Tuple[Document, float]] [source]¶
返回使用最大边际相关性选择的文档。最大边际相关性优化了与查询的相似性和所选文档之间的多样性。
- Parameters
query (str) – 要查找的查询。文本或图像或视频的路径。
k (int) – 要返回的文档数量。默认为 4。
fetch_k (int) – 要获取并传递给 MMR 算法的文档数量。
lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,其中 0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。
filter (Optional[Dict[str, str]]) – 按元数据过滤。默认为 None。
kwargs (Any) –
- Returns
由最大边际相关性选择的文档列表。
- Return type
List[Tuple[Document, float]]
- max_marginal_relevance_search_with_score_by_vector(embedding: List[float], k: int = 3, fetch_k: int = 15, lambda_mult: float = 0.5, filter: Optional[Dict[str, List]] = None, **kwargs: Any) List[Tuple[Document, float]] [source]¶
返回使用最大边际相关性选择的文档。最大边际相关性优化了与查询的相似性和所选文档之间的多样性。
- Parameters
embedding (List[float]) – 用于查找相似文档的嵌入向量。
k (int) – 要返回的文档数量。默认为 4。
fetch_k (int) – 要获取并传递给 MMR 算法的文档数量。
lambda_mult (float) – 介于 0 和 1 之间的数字,用于确定结果之间多样性的程度,其中 0 对应于最大多样性,1 对应于最小多样性。默认为 0.5。
filter (Optional[Dict[str, str]]) – 按元数据过滤。默认为 None。
kwargs (Any) –
- Returns
由最大边际相关性选择的文档列表。
- Return type
List[Tuple[Document, float]]
- query_collection_embeddings(query_embeddings: Optional[List[List[float]]] = None, collection_name: Optional[str] = None, n_results: int = 3, fetch_k: int = 15, filter: Optional[Dict[str, Any]] = None, results: Optional[Dict[str, Any]] = None, normalize_distance: bool = False, **kwargs: Any) List[Tuple[Dict[str, Any], List]] [source]¶
- Parameters
query_embeddings (Optional[List[List[float]]]) –
collection_name (Optional[str]) –
n_results (int) –
fetch_k (int) –
filter (Optional[Dict[str, Any]]) –
results (Optional[Dict[str, Any]]) –
normalize_distance (bool) –
kwargs (Any) –
- Return type
List[Tuple[Dict[str, Any], List]]
- search(query: str, search_type: str, **kwargs: Any) List[Document] ¶
Return docs most similar to query using a specified search type.
- Parameters
query (str) – Input text
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 = 3, fetch_k: int = 15, filter: Optional[Dict[str, List]] = None, **kwargs: Any) List[Document] [source]¶
Run similarity search with VDMS.
- Parameters
query (str) – 要查找的查询。文本或图像或视频的路径。
k (int) – Number of results to return. Defaults to 3.
fetch_k (int) – Number of candidates to fetch for knn (>= k).
filter (Optional[Dict[str, str]]) – 按元数据过滤。默认为 None。
kwargs (Any) –
- Returns
List of documents most similar to the query text.
- Return type
List[Document]
- similarity_search_by_vector(embedding: List[float], k: int = 3, fetch_k: int = 15, filter: Optional[Dict[str, List]] = None, **kwargs: Any) List[Document] [source]¶
Return docs most similar to embedding vector. :param embedding: Embedding to look up documents similar to. :type embedding: List[float] :param k: Number of Documents to return. Defaults to 3. :type k: int :param fetch_k: Number of candidates to fetch for knn (>= k). :type fetch_k: int :param filter: Filter by metadata. Defaults to None. :type filter: Optional[Dict[str, str]]
- Returns
与查询向量最相似的文档列表。
- Parameters
embedding (List[float]) –
k (int) –
fetch_k (int) –
filter (Optional[Dict[str, List]]) –
kwargs (Any) –
- 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 表示不相似,1 表示最相似。
- Parameters
query (str) – 输入文本。
k (int) – 要返回的文档数量。默认为 4。
**kwargs (Any) –
传递给相似性搜索的 kwargs。应包括:score_threshold: 可选,一个介于 0 到 1 之间的浮点值,用于
filter the resulting set of retrieved docs.
- Returns
元组列表,包含 (doc, similarity_score)。
- Return type
List[Tuple[Document, float]]
- similarity_search_with_score(query: str, k: int = 3, fetch_k: int = 15, filter: Optional[Dict[str, List]] = None, **kwargs: Any) List[Tuple[Document, float]] [source]¶
Run similarity search with VDMS with distance.
- Parameters
query (str) – 要查找的查询。文本或图像或视频的路径。
k (int) – Number of results to return. Defaults to 3.
fetch_k (int) – Number of candidates to fetch for knn (>= k).
filter (Optional[Dict[str, str]]) – 按元数据过滤。默认为 None。
kwargs (Any) –
- Returns
List of documents most similar to the query text and cosine distance in float for each. Lower score represents more similarity.
- Return type
List[Tuple[Document, float]]
- similarity_search_with_score_by_vector(embedding: List[float], k: int = 3, fetch_k: int = 15, filter: Optional[Dict[str, List]] = None, **kwargs: Any) List[Tuple[Document, float]] [source]¶
Return docs most similar to embedding vector and similarity score.
- Parameters
embedding (List[float]) – 用于查找相似文档的嵌入向量。
k (int) – Number of Documents to return. Defaults to 3.
fetch_k (int) – Number of candidates to fetch for knn (>= k).
filter (Optional[Dict[str, str]]) – 按元数据过滤。默认为 None。
kwargs (Any) –
- Returns
List of documents most similar to the query text. Lower score represents more similarity.
- 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 版本新增功能。
- update_document(collection_name: str, document_id: str, document: Document) None [source]¶
Update a document in the collection.
- Parameters
document_id (str) – 要更新的文档的 ID。
document (Document) – 要更新的文档。
collection_name (str) –
- Return type
None
- update_documents(collection_name: str, ids: List[str], documents: List[Document]) None [source]¶
Update a document in the collection.
- Parameters
ids (List[str]) – 要更新的文档的 id 列表。
documents (List[Document]) – 要更新的文档列表。
collection_name (str) –
- Return type
None
- 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 版本新增功能。