[Bug]: Document with NULL in a nullable vector column makes filter-only scans fail when include_vector=true ("fetch vector failed: Failed to fetch vector from index")

オープン
#791 コメント 2 件 リアクション 1 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@JalinWang がすでに取り組んでいます。

2026年10月21日 から。

  • #903 @JalinWang による — オープン

評価

この issue はまだ評価されていません。

説明

bug
Description

Description

A document written with NULL in a nullable VECTOR_FP32 column is
accepted by the write path (counted in WriteResult.SuccessCount and in
stats.doc_count, with only a log warning), but afterwards every
filter-only scan that requests vectors in its output fails
with an
InternalError instead of returning rows:

zvec error [InternalError]: Read next record batch failed (fill_result): ExecutionError in Gandiva: fetch vector failed:Failed to fetch vector from index

The write path therefore admits a state that a read path cannot consume.
Setting include_vector=false makes the identical scan succeed, so the
fault is in the query output-materialization path (the fill_result
stage): when materializing the vector column for the matched rows it
encounters the NULL and raises an internal error for the whole query
instead of yielding a NULL/absent cell.

Reachability: the Python and Node SDKs hardcode vector fields as
non-nullable and reject vector-less docs at doc validation, but the C/C++
SDKs and C-based SDKs (Go, Rust) allow nullable=true vector fields — the
state is created through those APIs (repro below uses the Go SDK).

Related issue: #691 documents the same underlying state (docs without
vectors in nullable vector fields) but only its read-back semantics
(fake all-zero placeholder returned, "nothing fails"). This report adds the
case where things do fail: listing scans, on an HNSW index. (#392/#393
also touched the include_vector=True path, but that was a format-version
mismatch, since fixed.)

Environment

  • zvec engine: v0.7.0 (built from source, AUTO_DETECT_ARCH=OFF; the
    failure is logic-level, not SIMD-related)
  • Go SDK: github.com/zvec-ai/zvec-go v0.7.0 (purego)
  • OS: Debian GNU/Linux, x86-64
  • Vector index: HNSW, cosine
Steps to Reproduce
## Steps to Reproduce


package main

import (
	"fmt"
	"log"
	"os"

	zvec "github.com/zvec-ai/zvec-go"
)

func must(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	must(zvec.Initialize(nil))
	defer zvec.Shutdown()

	path := "/tmp/zvec-null-repro"
	os.RemoveAll(path)

	schema := zvec.NewCollectionSchema("repro")
	idF := zvec.NewFieldSchema("id", zvec.DataTypeString, false, 0)
	inv, _ := zvec.NewInvertIndexParams(true, false)
	must(idF.SetIndexParams(inv))
	must(schema.AddField(idF))

	embF := zvec.NewFieldSchema("embedding", zvec.DataTypeVectorFP32, true /*nullable*/, 4)
	hnsw, _ := zvec.NewHNSWIndexParams(zvec.MetricTypeCosine, 16, 200)
	must(embF.SetIndexParams(hnsw))
	must(schema.AddField(embF))

	col, err := zvec.CreateAndOpen(path, schema, nil)
	must(err)
	defer col.Close()

	// d2 carries NULL in the vector column — accepted by the write path.
	d1, d2 := zvec.NewDoc(), zvec.NewDoc()
	d1.SetPK("d1")
	must(d1.AddStringField("id", "d1"))
	must(d1.AddVectorFP32Field("embedding", []float32{1, 0, 0, 0}))
	d2.SetPK("d2")
	must(d2.AddStringField("id", "d2"))
	must(d2.SetFieldNull("embedding"))

	wr, err := col.Upsert([]*zvec.Doc{d1, d2})
	must(err)
	fmt.Printf("upsert: success=%d error=%d\n", wr.SuccessCount, wr.ErrorCount)
	// -> upsert: success=2 error=0
	// (engine log: [WARN segment.cc:706] Field embedding not found or is
	//  null for doc: [op:1, doc_id: 1, score: 0, pk: d2, fields: 3]
	//  {"embedding": null, "tag": "b", "id": "d2"})

	// 1. filter-only scan, include_vector=true -> FAILS
	q := zvec.NewSearchQuery()
	must(q.SetTopK(10))
	must(q.SetFilter("id != ''"))
	must(q.SetIncludeVector(true))
	_, err = col.Query(q)
	q.Destroy()
	fmt.Println("scan  include_vector=true :", err)

	// 2. identical scan, include_vector=false -> OK
	q = zvec.NewSearchQuery()
	must(q.SetTopK(10))
	must(q.SetFilter("id != ''"))
	must(q.SetIncludeVector(false))
	res, err := col.Query(q)
	q.Destroy()
	fmt.Printf("scan  include_vector=false: %d rows, err=%v\n", len(res), err)
	zvec.FreeDocs(res)

	// 3. kNN only -> OK (the NULL-vector doc is silently excluded)
	q = zvec.NewSearchQuery()
	must(q.SetFieldName("embedding"))
	must(q.SetQueryVector([]float32{1, 0, 0, 0}))
	must(q.SetTopK(10))
	must(q.SetIncludeVector(true))
	res, err = col.Query(q)
	q.Destroy()
	fmt.Printf("knn   include_vector=true : %d hits, err=%v\n", len(res), err)
	zvec.FreeDocs(res)
}


### Behavior matrix (observed on v0.7.0)

| Query | include_vector | Result |
|---|---|---|
| kNN only (field + vector, no filter) | true | OK — the NULL-vector doc is silently excluded from hits |
| **filter-only scan** | **true** | **FAIL — `InternalError`, see error above** |
| filter-only scan (same data) | false | OK — both rows returned |
| kNN + scalar filter | true / false | OK |
| `Fetch` by PK, default options | false | OK — doc returned, vector field absent |
| `Fetch` by PK | true | doc returned without vector, after `[ERROR index.cc:633] Failed to fetch vector, doc_id: 1` and `[ERROR segment.cc:1319] vector indexer fetch failed, ...` |
| NULL in a nullable **scalar** column + filter scan | n/a | OK — scalar NULLs are harmless |

`stats.doc_count` counts the NULL-vector document and
`IndexCompleteness=0` is reported for the embedding index, confirming the
engine's own bookkeeping accepts the state.

## Expected Behavior

One of (in order of preference):

1. The scan succeeds and the vector cell is returned as NULL/absent for
   that row — NULL should behave consistently across kNN (excluded),
   fetch (field dropped) and scans (currently: fatal).
2. Schema validation rejects `nullable=true` on vector fields, so the
   unqueryable state can never be written.
3. At minimum, document the constraint prominently and warn (not just log)
   at ingest time.

## Actual Behavior

The whole query fails with `InternalError` once a single NULL-vector
document exists in the collection; listing scans become unusable and the
failure surfaces at read time, after the data has already been accepted.

## Key Observations

- The failure is specific to the **output path** (`fill_result`), not to
  filter evaluation: the identical scan succeeds with
  `include_vector=false`, and filters over NULL *scalar* values work.
- kNN never fails because unscorable NULL-vector documents are excluded
  from top-k before result materialization; only scans whose result set
  *contains* a NULL-vector row trigger the fault.
- #691's placeholder mechanism (zero-vector placeholder under
  `kInvalidKey`) covers the Flat streamer; this report used HNSW, where
  materialization instead raises — the two symptoms together suggest the
  NULL-vector story is incomplete across index types.

## Suggested Fix

- Return NULL/absent for the vector cell in the materialized batch, or
- reject nullable vector fields at schema validation, or
- reject NULL vectors at write time with a per-doc error
  (`WriteResult.ErrorCount` already exists as a mechanism).
Logs / Stack Trace
The failure is an **error returned from `Query`** — not a crash — so there
is no backtrace to attach. The engine output below is verbatim from the
probe run (schema: `id` string, `tag` nullable string, `embedding` nullable
vector; doc `d2` carries the NULL vector; timestamp/thread-id prefixes
trimmed):


-- 1) Ingest of the NULL-vector doc is ACCEPTED, with only a warning:

[WARN segment.cc:706] Field embedding not found or is null for doc: [op:1, doc_id: 1, score: 0, pk: d2, fields: 3]{"embedding": null, "tag": "b", "id": "d2"}

   upsert result: success=2 error=0
   stats: doc_count=2, index_count=1, IndexCompleteness=[0]

-- 2) Filter-only scan, include_vector=true — the whole query fails:

zvec error [InternalError]: Read next record batch failed (fill_result): ExecutionError in Gandiva: fetch vector failed:Failed to fetch vector from index

   accompanied on the engine log by:

[ERROR index.cc:633] Failed to fetch vector, doc_id: 1

-- 3) The identical scan with include_vector=false succeeds (2 rows, no log output).

-- 4) Fetch-with-vector of the NULL doc also fails to materialize (doc is
   returned without the vector field):

[ERROR index.cc:633] Failed to fetch vector, doc_id: 1
[ERROR segment.cc:1319] vector indexer fetch failed, column: embedding, doc_count: 1, mem_block_offset: 0, block_doc_id: 1


The process stays healthy throughout — no SIGSEGV/SIGABRT. The NULL-vector
row was written by the engine itself (with only the WARN in 1) and is then
unreadable through scan/fetch materialization. Deterministic across runs.
Operating System

Debian GNU/Linux 13.7, x86-64

Build & Runtime Environment
  • zvec engine: v0.7.0 (built from source, AUTO_DETECT_ARCH=OFF; the failure is logic-level, not SIMD-related) - Go SDK: github.com/zvec-ai/zvec-go v0.7.0 (purego) - Vector index: HNSW, cosine
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)
主要言語
C++
スター
16.3k
フォーク
1k
平均マージ
2日 10時間
マージ済み PR(30日)
32

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

alibaba/zvec のほかの issue

alibaba/zvec の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。