别人网站 自己的二级域名,大连经济,免费把图片生成链接,wordpress怎么改端口Qdrant 是近年来非常热门的向量数据库#xff0c;广泛用于文本搜索、推荐系统、图像相似度匹配等场景。本文将带你从最实用的三个层面入手#xff0c;快速上手并用好 Qdrant 的核心能力#xff1a; ✅ 远程连接配置详解 #x1f3d7;️ 集合创建参数全面解释 #x1f50… Qdrant 是近年来非常热门的向量数据库广泛用于文本搜索、推荐系统、图像相似度匹配等场景。本文将带你从最实用的三个层面入手快速上手并用好 Qdrant 的核心能力 ✅ 远程连接配置详解 ️ 集合创建参数全面解释 查询参数高级用法 本例为Qdrant 1.14.2注意 ✅ 一、远程连接配置详解QdrantClient 在本地你可以用 host 和 port 来连接 Qdrant 服务而在生产中通常使用 Qdrant Cloud 提供的 HTTPS 接口和 API 密钥
from qdrant_client import QdrantClientclient QdrantClient(urlhttps://your-qdrant-endpoint.qdrant.io,api_keyyour-api-key-here
) 参数 类型 说明 url str Qdrant 服务的远程地址必须是 HTTPS api_key str API 密钥保护访问权限 timeout int/float 可选请求超时默认 5 秒 prefer_grpc bool 可选是否优先使用 gRPC速度更快但需服务器支持 本地开发
client QdrantClient(hostlocalhost, port6333) ️ 二、创建集合Collection参数详解 向量搜索的前提是集合Collection它类似于表结构用于存储向量及其 metadata。下面是一个完整的创建集合示例
from qdrant_client.http.models import VectorParams, Distanceclient.create_collection(collection_namec_names,vectors_configVectorParams(size4,distanceDistance.COSINE)
)points [PointStruct(idstr(uuid.uuid4()), vector[0.1, 0.2, 0.3, 0.4], payload{name: Tokyo}),PointStruct(idstr(uuid.uuid4()), vector[0.2, 0.1, 0.4, 0.3], payload{name: Kyoto}),
]client.upsert(collection_namec_names, pointspoints)
print(✅ 已插入测试数据)✳️ 参数解析 参数名 说明 collection_name 集合名称自定义 size 向量维度取决于你的 embedding 模型 distance 相似度计算方式推荐使用 COSINE 常见模型维度对照 模型名称 维度size MiniLM-L12-v2 384 e5-base 768 text-embedding-3-small 1536 ️ 可选参数进阶 参数名 说明 on_disk_payload 是否将 payload 存储到磁盘节省内存 hnsw_config 索引构建参数可优化召回速度 三、查询参数详解
query_points() 实战 Qdrant 旧接口 search() 已弃用推荐使用新版 query_points()。这是最常用的检索 API支持分页、筛选、相似度阈值等强大功能
from qdrant_client.http.models import QueryVectorresults client.query_points(collection_namec_names,query[0.1, 0.2, 0.3, 0.4],limit5,with_payloadTrue,score_threshold0.9
)print( 查询结果)
for r in result.points:print(f- id: {r.id}, score: {r.score}, payload: {r.payload}) 参数详解 参数名 类型 说明 collection_name str 要查询的集合名 query QueryVector 查询向量维度必须匹配 limit int 返回结果数量上限 with_payload bool 是否返回 metadata如地名 score_threshold float 仅返回相似度高于该阈值的记录 offset int 分页偏移量跳过前N条 filter Filter 对象 高级筛选条件如国家名 score_threshold 使用技巧 如果你希望结果尽量“接近”原始向量可以使用 score_threshold比如
score_threshold0.95
这意味着只保留相似度高于 0.95 的结果常用于高置信度翻译、名称匹配等场景。 高级筛选按字段过滤
filter from qdrant_client.http.models import Filter, FieldCondition, MatchValuemy_filter Filter(must[FieldCondition(keycountry,matchMatchValue(valueJapan))]
)
然后作为参数传入
results client.query_points(collection_nameplace_names,query[...],filtermy_filter,limit10
) 总结速查表 场景 推荐配置 文本相似搜索 distanceCOSINE 384 维 精准匹配 加入 score_threshold0.9 分类过滤 使用 filter 结合 payload 排查效果 开启 with_vectorsTrue 查看返回向量 附加建议 使用 sentence-transformers 快速生成文本向量 本地测试建议使用 Docker 启动 Qdrant 在线部署推荐使用 Qdrant Cloud支持备份与权限管理 API 更新频繁记得关注 官方文档。