Skip to content

[Bug]: load from file,using vector to search failed #227

@DarthVaderYTX

Description

@DarthVaderYTX

Description

`import os.path

import zvec
from zvec import VectorSchema, VectorQuery, FieldSchema

Define collection schema

schema = zvec.CollectionSchema(
name="example",
fields=[
FieldSchema("user_id", data_type=zvec.DataType.STRING, nullable=True),
FieldSchema("name", data_type=zvec.DataType.STRING, nullable=True),
],
vectors=[
zvec.VectorSchema("embedding", zvec.DataType.VECTOR_FP32, 4),
zvec.VectorSchema("embedding2", zvec.DataType.VECTOR_FP32, 4)
],
)

Create collection

path = "./zvec_example"
if os.path.exists(path):
collection = zvec.open(path=path,option=zvec.CollectionOption(read_only=False, enable_mmap=True))
else:
collection = zvec.create_and_open(path=path, schema=schema,option=zvec.CollectionOption(read_only=False, enable_mmap=True))
print(collection.stats)

Insert documents

status = collection.upsert([
zvec.Doc(id="doc_1", vectors={"embedding": [0.1, 0.2, 0.3, 0.4], "embedding2": [0.2, 0.3, 0.4, 0.1]},fields={"user_id":"123","name":"jack"}),
zvec.Doc(id="doc_2", vectors={"embedding": [0.2, 0.3, 0.4, 0.1], "embedding2": [0.1, 0.2, 0.3, 0.4]},fields={"user_id":"456","name":"pony"}),
])
print(status)

Search by vector similarity

results = collection.query(
zvec.VectorQuery("embedding", vector=[0.4, 0.3, 0.3, 0.1]),
topk=10,
include_vector=True,
output_fields=["user_id","name"],
)

Results: list of {'id': str, 'score': float, ...}, sorted by relevance

print(results)
print(len(results))

d = collection.query(include_vector=True)
print(len(d))`

Steps to Reproduce

1. when create the zvec file first, it can search by vector success
2. when load the database from file, search by vector failed

Logs / Stack Trace

Operating System

macOS

Build & Runtime Environment

python 3.10

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)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions