zvec icon indicating copy to clipboard operation
zvec copied to clipboard

[Bug]: query(include_vector=True) raises "Dimension not match:3 vs 11" on FlatIndex

Open zhzjm opened this issue 6 months ago • 1 comments

Description

ValueError: Dimension not match:3 vs 11 File "zvec/executor/query_executor.py", line 189, in _do_execute docs = collection.Query(query) Triggered by: collection.query(vectors=vq, topk=N, include_vector=True) Reproduced on: zvec==0.3.0, fresh collection, FlatIndex, 384d

Steps to Reproduce

## Steps to Reproduce
1. Install zvec==0.3.0 (or 0.3.1):

pip install zvec==0.3.0
2. Create a collection with FlatIndex on 384-dim vectors:
import zvec
from zvec import (
    CollectionSchema, FieldSchema, VectorSchema,
    DataType, FlatIndexParam, MetricType, VectorQuery,
)
schema = CollectionSchema(
    name="documents",
    fields=[
        FieldSchema("doc_id", DataType.STRING, nullable=False),
        FieldSchema("title", DataType.STRING, nullable=True),
        FieldSchema("content", DataType.STRING, nullable=True),
    ],
    vectors=[
        VectorSchema(
            "context_vec",
            DataType.VECTOR_FP32,
            dimension=384,
            index_param=FlatIndexParam(metric_type=MetricType.COSINE),
        ),
    ],
)
collection = zvec.create_and_open("/tmp/test_collection", schema=schema)
3. Insert a document:
import numpy as np
vec = np.random.randn(384).astype(np.float32).tolist()
doc = zvec.Doc(
    id="test_doc_1",
    fields={"doc_id": "test_doc_1", "title": "test"},
    vectors={"context_vec": vec},
)
collection.insert([doc])
collection.flush()
4. Query with include_vector=True:
vq = VectorQuery(field_name="context_vec", vector=[0.0] * 384)
results = collection.query(vectors=vq, topk=10, include_vector=True)
# ^^^ THIS FAILS with:
# ValueError: Dimension not match:X vs 11
5. Query with include_vector=False succeeds:
results = collection.query(vectors=vq, topk=10, include_vector=False)
# ^^^ WORKS, but doc.vectors.get("context_vec") returns None
Expected Behavior
query(include_vector=True) should return the stored vectors, as documented at https://zvec.org/api-reference/python/collection/
Actual Behavior
Raises ValueError: Dimension not match:3 vs 11 (or 4 vs 11, varying between builds). The number 11 appears to be a fixed file format version stored in the collection data, while 3/4 is the format version expected by the current zvec library.
Environment
- OS: Linux x86_64 (Docker container)
- Python: 3.11
- zvec version: 0.3.0 (also tested on 0.3.1 - same behavior)
- Index type: FlatIndex
- Vector dimension: 384

Logs / Stack Trace


Operating System

Linux x86_64 (Docker container)

Build & Runtime Environment

  • Python: 3.11 - zvec version: 0.3.0 (also tested on 0.3.1 - same behavior) - Index type: FlatIndex - Vector dimension: 384

Additional Context

  • [ ] I've checked git status — no uncommitted submodule changes
  • [ ] I built with CMAKE_BUILD_TYPE=Debug
  • [ ] This occurs with or without COVERAGE=ON
  • [ ] The issue involves Python ↔ C++ integration (pybind11)

zhzjm avatar May 11 '26 15:05 zhzjm

Closed as duplicate to #393

zhourrr avatar May 12 '26 02:05 zhourrr