OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug] Embedding pipeline does not chunk oversized files — files exceeding embedding model ctx-size fail silently

Open wyl1988 opened this issue 4 months ago • 1 comments

Bug Description

When OV's embedding pipeline encounters a file that exceeds the embedding model's context window, it does not chunk the file. Instead, it attempts single-shot embedding, which fails with a 400/500 error from the embedding server. The file is then never vectorized — it becomes a "dead memory" that exists on disk but is never searchable via viking_search.

Issue #731 reported the error symptom ("Input sequence length exceeds max input length") and was closed, and issues #530/#531 discussed chunking strategy. However, in the current release (0.4.5+), files exceeding the embedding model's context window still fail silently — there is no automatic chunking for memory file vectorization.

Impact

In our deployment with Qwen3-Embedding-4B (ctx=2560):

  • 22+ memory files exceed 2560 tokens at time of writing
  • Each of these files triggers embedding 400/500 errors
  • Errors accumulate in .failed.json files
  • The files are permanently unsearchable unless manually chunked

There is a time gap problem too: new large memory files are written by session extraction at any time, but our chunking cron runs only once daily at 04:00. Files written at other times remain broken for hours.

Reproduction

  1. Configure OV with a local embedding model that has a limited context window (e.g., ctx=2560)
  2. Have a session that produces a large memory file (>2560 tokens)
  3. Observe embedding errors in OV logs: Input sequence length exceeds the max input length
  4. Try viking_search for content from that file — it will not return

Workaround Applied

We wrote ov-memory-chunker.py (runs daily via cron at 04:00) to:

  1. Scan all memory files for oversized entries
  2. Split them using paragraph-then-line strategy
  3. Each fragment gets a _c01, _c02 suffix
  4. OV then re-embeds the fragments

This produces 509+ chunk fragments in our deployment — 40% of all memory files. The fragments lack standalone semantic completeness.

Expected Behavior

OV should either:

  1. Chunk automatically: Split files exceeding the embedding model's context window before vectorization, similar to how resources are handled
  2. Truncate with warning: If chunking is not feasible, truncate the input and log a warning instead of failing silently
  3. Expose config: Allow embedding.max_input_tokens in ov.conf to control chunking behavior

Environment

  • OpenViking: 0.4.5+
  • Embedding: Qwen3-Embedding-4B Q6_K GGUF (local, ctx=2560)
  • 22+ oversized files, 509+ chunk fragments from manual chunking

wyl1988 avatar Jul 04 '26 04:07 wyl1988

Thanks for reporting this!

This path goes through the main embedding queue, and current OpenViking bounds provider-facing embedding input via embedding.max_input_tokens. For a local model with ctx=2560, please set this below the model context window, for example:

{
  "embedding": {
    "max_input_tokens": 2048
  }
}

This is a truncation guard, not automatic chunking. After updating the config, please reindex or retry the affected memory files so previously failed entries can be embedded again.

qin-ctx avatar Jul 06 '26 04:07 qin-ctx