get - 检索
get() 用于在不进行向量相似性搜索的情况下,从 collection 中搜索 documents。
它支持按 IDs、 metadata、和 document 过滤。
信息
仅支持在使用 Client 连接时,才能使用该接口。关于 Client 的详细介绍,参见 Client。
前提条件
-
您已经安装了 pyseekdb,有关安装 pyseekdb 的详细信息,参见 快速开始。
-
您已经连接到数据库。有关连接的详细操作参见 Client。
-
您已经创建了 collection,并插入相应的数据。有关创建 collection 和插入数据的详细操作参见 create_collection - 创建 Collection 和 add - 插入数据。
请求参数
get()
| 参数 | 取值类型 | 是否必选 | 描述 | 取值示例 |
|---|---|---|---|---|
ids | List[float] or List[List[float]] | 必选 | 要检索的单个 ID 或 ID 列表 | [1.0, 2.0, 3.0] |
where | dict | 可选 | Metadata 筛选条件。 | {"category": {"$eq": "AI"}} |
where_document | dict | 可选 | Document 筛选条件。 | {"$contains": "machine"} |
limit | dict | 可选 | 要返回的最大结果数。 | {"category": {"$eq": "AI"}} |
offset | dict | 可选 | 分页时要跳过的结果数。 | {"$contains": "machine"} |
include | List[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 对象。