[Bug] File-level embeddings are generated and stored, but search never returns file-level results (v0.4.16, local deployment)
[Bug] File-level embeddings are generated and stored, but search never returns file-level results (v0.4.16, local deployment)
Environment
- OpenViking: v0.4.16 (pip install, local backend for both AGFS and vectordb)
- Embedding: local Ollama (bge-m3, 1024 dims)
- OS: Ubuntu 24.04, Python 3.12
Summary
When writing memory files via POST /api/v1/content/write, file-level embeddings are successfully generated (confirmed by queue status). However, POST /api/v1/search/find and POST /api/v1/search/search never return individual file results — only directory-level abstracts (.abstract.md).
Reproduction
Step 1: Write a memory file with a unique keyword
curl -X POST http://127.0.0.1:1933/api/v1/content/write \
-H "X-Api-Key: $USER_KEY" -H "Content-Type: application/json" \
-d '{
"uri": "viking://user/testuser/memories/entities/mem_test.md",
"content": "UNIQUEKEYWORD12345 test content for vector index verification",
"mode": "create",
"wait": true
}'
Step 2: Confirm embedding was generated
Response includes:
{
"vector_status": "complete",
"queue_status": {
"Embedding": {
"processed": 1,
"requeue_count": 0,
"error_count": 0
}
}
}
This confirms the file-level embedding was queued, processed, and stored successfully.
Step 3: Search for the unique keyword
curl -X POST http://127.0.0.1:1933/api/v1/search/find \
-H "X-Api-Key: $USER_KEY" -H "Content-Type: application/json" \
-d '{"query": "UNIQUEKEYWORD12345", "limit": 5}'
Expected: The file mem_test.md should appear in results.
Actual: Returns 0 file-level results. Only the parent directory's .abstract.md is returned (if it happens to contain related terms in its summary).
Additional test: search with level=[2]
curl -X POST http://127.0.0.1:1933/api/v1/search/search \
-d '{"query": "UNIQUEKEYWORD12345", "limit": 5, "level": [2]}'
Result: Empty. No level-2 results at all.
What we've verified
| Check | Result |
|---|---|
| File exists on disk | ✅ |
| Embedding generated (queue processed, 0 errors) | ✅ |
| Vector database has data (7.7MB for ~300 files) | ✅ |
| Directory abstracts are searchable | ✅ |
| Individual file contents are searchable | ❌ Never |
| Works for auto-extracted memories | ❌ Same issue |
| Works for manually migrated memories | ❌ Same issue |
| Rerank (qwen3-rerank via DashScope) is called and functional | ✅ (metrics confirm calls) but only reranks directory abstracts |
HierarchicalRetriever initialized with rerank |
✅ |
Analysis of likely cause
Tracing through HierarchicalRetriever.retrieve():
- Global vector search (Step 2) → returns directory-level results → these become
starting_points _recursive_search()(Step 4) → should find file-level entries within directories- File-level entries from recursive search should get rerank scores (line 500-502)
_convert_to_matched_contexts()reads_final_score(which includes rerank)
The issue appears to be in step 2: the recursive search within directories is not returning file-level vector matches, even though the embeddings exist in the vector database.
Possibly related: has_queue_manager check in refresh_file_embedding() — but our queue manager IS active (embeddings are processed). The issue may be in how the vector search query is constructed (e.g., filtering by level, or using a different collection for the global vs. recursive search).
Impact
- All file-level memory content is unsearchable
- Search only works at "which directory to look in" granularity
- Rerank is wasted (only reranks directory summaries)
- Significantly degrades memory retrieval quality vs. simpler systems (e.g., SQLite FTS5)
Question for maintainers
Is this a known limitation of the local deployment? Or is there a configuration step we're missing to enable file-level search? Issue #754 (fix: preserve level-2 rerank scores) suggests file-level results are expected to work.
I'd like to work on a focused reproduction and fix for this.
On current main, the hierarchical path has a deterministic premature-stop case that matches the reported deep memory URI: _recursive_search() increments stagnant_rounds whenever the result pool does not grow, even while its directory queue still contains unvisited descendants. With the default two-round limit, a path such as memories -> entities -> mem_test.md can stop before the level-2 file's parent is expanded, because the first rounds discover only directories and therefore add no result candidates.
I plan to keep the first patch local until the behavior is verified:
- add an offline regression proxy with more than two directory levels and a searchable level-2 leaf,
- prove current
mainreturns no leaf, - make convergence depend on having enough result candidates rather than treating directory-only traversal as stagnation, and
- run the focused retrieval suite plus Ruff/format checks.
This would not change vector creation, scoring, ACL filtering, or public result shapes. I also checked the current open PRs: several touch retrieval, but none references #4482 or addresses this premature convergence condition. @zhoujh01, please let me know if this matches the intended traversal semantics or if you would prefer a different stopping rule.
Correction after running the offline reproduction: my initial convergence hypothesis was not the failing path. A three-level directory-only traversal reaches its level-2 leaf on current main, so I discarded that change.
The verified trigger is the combination reported here: a reranker selects THINKING mode, while a local deployment has no ACL manager. In that branch, current main performs the global level=[2] vector search only when self.vector_store.acl_manager is not None. The same stored level-2 vector is therefore queried in ACL deployments but skipped in non-ACL local deployments. Hierarchical traversal cannot reliably compensate when the unique term exists only in the file body and no parent directory ranks into the relevant path.
I now have a local two-case red/green regression for default level=None and explicit level=[2]:
- baseline: 2 failed, both returned no file and issued only the
[0, 1]search; - one-line fix: 2 passed and issued
[0, 1]followed by[2]; - full
tests/retrieve: 60 passed; - Ruff lint and changed-range format checks: passed.
The production change only removes the ACL-manager guard from the already-existing leaf search; tenant, target-directory, extra-filter, and ACL scope construction remain inside search_in_tenant(). I have kept commit 9f582bc4 local and will not push or open a PR until the retrieval owner confirms that global level-2 search is intended for non-ACL THINKING mode as well.
@xbyzr Thanks for the report. I can reproduce the issue with rerank enabled.
The L2 embedding itself is written successfully. The failure happens when the hierarchical search path cannot reach that L2 file through an indexed L0/L1 parent entry.
With rerank enabled, search uses the hierarchical THINKING path: it first retrieves L0/L1 directory entries, then searches their children. If the parent directory overview is missing, skipped, or not updated/indexed for the new file, the retriever will not enter that directory, so the L2 file remains unreachable.
With rerank disabled, retrieval uses the QUICK path, which directly performs a global L2 vector search, so the same file can be found.
Ablation results:
| Version / config | Write target | Rerank | Extra step | find level=[2] |
search level=[2] |
Result |
|---|---|---|---|---|---|---|
latest main |
new memory directory | off | none | ✅ found | ✅ found | QUICK retrieval directly searches L2 |
v0.4.16 |
new memory directory | on | none | ❌ not found | ❌ not found | rerank path depends on L0/L1 directory traversal |
latest main |
new memory directory | on | none | ✅ found | ❌ not found | find now uses QUICK, but search still uses hierarchical rerank path |
latest main |
existing indexed directory, e.g. memories/entities |
on | none | ✅ found | ✅ found | parent L0/L1 entry exists, so hierarchical traversal can reach L2 |
latest main |
new memory directory | on | reindex semantic_and_vectors on parent dir |
✅ found | ✅ found | reindex creates/updates parent L0/L1, making L2 reachable |
A workaround is to reindex the parent directory after the write:
curl -X POST http://127.0.0.1:1933/api/v1/content/reindex \
-H "X-Api-Key: $USER_KEY" \
-H "Content-Type: application/json" \
-d '{
"uri": "viking://user/testuser/memories/entities",
"mode": "semantic_and_vectors",
"wait": true,
"recursive": false
}'
Note that mode must be semantic_and_vectors; the default vectors_only only rebuilds vectors and does not create/update L0/L1 directory summaries.
Thanks for the detailed ablation; this corrects my earlier diagnosis. I rechecked current main (c486088e) and the API memory-write path still refreshes only the memory-type root overview before embedding the L2 file, so a newly introduced direct parent can remain absent from the L1 index.\n\nCompetition/history audit found two existing PRs that matter before another implementation is opened:\n\n- #3679 already implements direct-parent overview refresh + L1 vectorization for API memory writes, which matches this root cause, but its core commit no longer cherry-picks cleanly onto current main because both content-write and semantic-processing paths have since changed.\n- #3135 instead adds L2 results to global THINKING search; it has an unresolved Changes Requested review because it also feeds L2 documents into directory traversal.\n\nI will not submit my earlier ACL-guard patch: it addresses the wrong boundary and would overlap these efforts. If maintainers prefer a fresh minimal extraction of only #3679's API-write parent-indexing behavior onto current main, please confirm/assign that direction; otherwise #3679 should remain the ownership path.