fix(mappings): support any embedding dimension on Elasticsearch (#20368)

This commit is contained in:
qinling0210 authored and GitHub committed 2026-09-29 17:46:45 +08:00
1 parent b85aa51c07
commit 02569aee9d
2 files changed
+5 -43

No files matched your search

+2 -36
View File
@@ -159,45 +159,11 @@
},
{
"dense_vector": {
"match": "*_512_vec",
"match": "q_*_vec",
"mapping": {
"type": "dense_vector",
"index": true,
"similarity": "cosine",
"dims": 512
}
}
},
{
"dense_vector": {
"match": "*_768_vec",
"mapping": {
"type": "dense_vector",
"index": true,
"similarity": "cosine",
"dims": 768
}
}
},
{
"dense_vector": {
"match": "*_1024_vec",
"mapping": {
"type": "dense_vector",
"index": true,
"similarity": "cosine",
"dims": 1024
}
}
},
{
"dense_vector": {
"match": "*_1536_vec",
"mapping": {
"type": "dense_vector",
"index": true,
"similarity": "cosine",
"dims": 1536
"similarity": "cosine"
}
}
},
+3 -7
View File
@@ -288,13 +288,9 @@ func (stubNavEmbedder) Encode(_ context.Context, _ string, texts []string) ([][]
out := make([][]float32, len(texts))
for i, t := range texts {
// The ES document index template (mapping.json, the ragflow_*
// dynamic_templates) maps q_<dim>_vec to a dense_vector field only for
// the standard embedding dimensions 512/768/1024/1536. The integration
// test runs NavService.Search as a real knn query against that index,
// so the synthetic vector must use one of those dimensions — otherwise
// ES dynamically maps q_<dim>_vec as a plain float array and the knn
// query fails with "[knn] queries are only supported on [dense_vector]
// fields". 1024 is the canonical RAGFlow embedding size.
// dynamic_templates) maps any q_<dim>_vec field to dense_vector, so the
// synthetic vector may use any dimension. 1024 is the canonical
// RAGFlow embedding size.
dim := 1024
v := make([]float32, dim)
for d := 0; d < dim; d++ {