跳到主要内容

get - 检索

get() 用于在不进行向量相似性搜索的情况下,从 collection 中搜索 documents。

它支持按 IDs、 metadata、和 document 过滤。

信息

仅支持在使用 Client 连接时,才能使用该接口。关于 Client 的详细介绍,参见 Client

前提条件

请求参数

get()
参数取值类型是否必选描述取值示例
idsList[float] or List[List[float]]必选要检索的单个 ID 或 ID 列表[1.0, 2.0, 3.0]
wheredict可选Metadata 筛选条件。{"category": {"$eq": "AI"}}
where_documentdict可选Document 筛选条件。{"$contains": "machine"}
limitdict可选要返回的最大结果数。{"category": {"$eq": "AI"}}
offsetdict可选分页时要跳过的结果数。{"$contains": "machine"}
includeList[str]可选要包含的字段列表:["documents", "metadatas", "embeddings"]["documents", "metadatas", "embeddings"]
信息

如果没有提供参数,则返回所有数据。

请求示例

import pyseekdb

# Create a client
client = pyseekdb.Client()

collection = client.get_collection("my_collection")

# Get by single ID
results = collection.get(ids="123")

# Get by multiple IDs
results = collection.get(ids=["1", "2", "3"])

# Get by metadata filter
results = collection.get(
where={"category": {"$eq": "AI"}},
limit=10
)

# Get by comparison operator
results = collection.get(
where={"score": {"$gte": 90}},
limit=10
)

# Get by $in operator
results = collection.get(
where={"tag": {"$in": ["ml", "python"]}},
limit=10
)

# Get by logical operators ($or)
results = collection.get(
where={
"$or": [
{"category": {"$eq": "AI"}},
{"tag": {"$eq": "python"}}
]
},
limit=10
)

# Get by document content filter
results = collection.get(
where_document={"$contains": "machine learning"},
limit=10
)

# Get with combined filters
results = collection.get(
where={"category": {"$eq": "AI"}},
where_document={"$contains": "machine"},
limit=10
)

# Get with pagination
results = collection.get(limit=2, offset=1)

# Get with specific fields
results = collection.get(
ids=["1", "2"],
include=["documents", "metadatas", "embeddings"]
)

# Get all data (up to limit)
results = collection.get(limit=100)

返回参数

  • 如果提供单个 ID:返回结果包含该 ID 的 get 对象。
  • 如果提供多个 IDs:列出 QueryResult 对象,一个 ID 对应一个。
  • 如果提供了过滤器:包含所有匹配结果的 QueryResult 对象。

相关操作