Appearance
过滤条件
作用
只在满足 Payload 条件 的点中进行向量检索,例如:
- 仅某用户可见的文档:
user_id == 123 - 某时间范围:
created_at在某区间内 - 语言:
lang == "zh"
Python 示例
python
from qdrant_client.models import Filter, FieldCondition, MatchValue
hits = client.search(
collection_name="demo_text",
query_vector=[0.1] * 384,
limit=10,
query_filter=Filter(
must=[
FieldCondition(key="lang", match=MatchValue(value="zh")),
]
),
)must:全部满足;还有 should(或)、must_not(非)等组合,见官方 Filter 文档。
Java 示例
java
import static io.qdrant.client.ConditionFactory.matchKeyword;
import io.qdrant.client.grpc.Points.Filter;
import io.qdrant.client.grpc.Points.SearchPoints;
var hits = client.searchAsync(
SearchPoints.newBuilder()
.setCollectionName("demo_text")
.addAllVector(queryVectorList)
.setFilter(Filter.newBuilder()
.addMust(matchKeyword("lang", "zh"))
.build())
.setLimit(10)
.build()
).get();索引
对 lang、user_id 等过滤字段务必创建 payload index,否则大集合上过滤会很慢。
常见错误
- 字段类型与 match 不匹配(如对数字字段用 keyword match)。
- 未建索引导致超时——在 Dashboard 或 API 中为该 key 创建索引。
下一节:滚动与分页(遍历全量点)。