建索引(8.x 写法)
建索引(8.x 写法)
PUT kb_chunks
{
"mappings": {
"properties": {
"content": { "type": "text" },
"embedding": {
"type": "dense_vector",
"dims": 1024,
"index": true,
"similarity": "cosine"
}
}
}
}kNN 检索
kNN 检索
POST kb_chunks/_search
{
"knn": {
"field": "embedding",
"query_vector": [0.1, 0.2, 0.3],
"k": 10,
"num_candidates": 100
},
"_source": ["content", "source"]
}dims 与模型输出必须一致;8.x 起向量索引基于 HNSW,num_candidates 影响召回与延迟。