Why Vector, Keyword, and Neo4j Use Different Stores
Semantic similarity, exact identifiers, and relationship traversal are three different query problems; forcing them into one database sacrifices correctness and explainability.
On this page · 11 sections
Three questions need three capabilities:
- “Which code does this configuration label correspond to?” needs semantic recall.
- “Where is
RebuildProjectionJobdefined?” needs an exact identifier. - “Which provider does it ultimately call?” needs path traversal that is directed, typed, and backed by evidence.
These three questions differ in data structure and in scoring. Hand all of them to one “do-everything database” and at least one class of question ends up distorted.
mt_rag uses polyglot persistence, that is, a different store for each kind of query: Qdrant handles dense vectors, SQLite FTS and exact aliases handle lexical identity, and Neo4j handles canonical relations. CAS and the manifest remain the fact and version foundation underneath all of them.
The Short Version
- Semantic similarity, exact identifiers, and relationship traversal are three different query problems; forcing them into one database distorts at least one of them.
- The split: Qdrant is responsible for similarity, SQLite FTS and exact aliases guard code identity, and Neo4j stores only the traversable semantic graph. CAS and the manifest are the fact and version foundation.
- The three stores share no transaction. Stable IDs, the manifest, independent cursors, and idempotent upserts/deletes give detectable eventual consistency, and a query cannot stitch together results from different generations.
- External callers should use only
POST /v1/answeror/v1/answer/stream, never the stores directly.
Knowledge Map for This Article
The concepts here are the dense index, the lexical index, exact identity, graph traversal, parent/child context, projection consistency, and the external API boundary.
First, Separate the Four Current Runtime Planes
The project currently retains four kinds of usage, and they cannot be described as one production chain that has already been fully cut over:
- The rich batch from
data/01-rawthroughdata/07-manifest, used for maintenance-time full or partial rebuilds. - The V3 event fast lane, which uses the journal and cursors to project day-to-day changes into vector and graph.
- The default external
/v1/answer, which uses Qdrant throughanswer-qdrant-local, can also compare against zvec/pgvector, and optionally uses Neo4j. - The current System RAG shadow query, which uses its own manifest, Qdrant collection, keyword DB, and canonical system graph, and has not been cut over.
This chapter covers the storage responsibilities they share. Wherever it touches the strict 70/30 split, the canonical graph, or the generation gate, it refers specifically to System RAG shadow. Readiness cannot automatically turn the shadow into the production store behind the external API.
Qdrant: Responsible for Similarity, Not for Relationship Proof
System RAG embedding currently uses the local Qwen/Qwen3-Embedding-0.6B: 1024 dimensions, cosine distance. The active system runtime configures max_seq_length as 2048; the configuration separately holds a model-capability profile that records 8192. The two must not be conflated. At runtime, the actual embedding configuration and the index manifest are authoritative.
The written payload contains more than text. It also preserves:
source_id / source_type / chunk_id / parent_id
title / summary / locator / graph_ids
original_content_hash / original_cas_uri
repository / commit_sha / file_path / symbol
freshness or currentness fields
Before a query, the system verifies that the query embedder's model, dimension, and runtime profile match the index manifest exactly. A lagging source manifest generation or vector consumer cursor is reported directly as stale. The same 1024-dimension embedding cache can also feed the zvec and pgvector comparisons, so “model quality” and “store implementation” can be measured separately.
The graph_ids in a vector payload are only jump anchors, not the relationships themselves. Stuffing calls=[...] into the payload can display one layer of neighbors, but it cannot efficiently answer direction, relation type, path length, or the evidence behind each edge.
SQLite FTS and Exact Alias: Guarding Code Identity
The system keyword DB has three key structures:
chunks: stores child/parent text, source identity, and payload.- The FTS5 table
chunks_fts: indexes only the title, summary, and text of children, using the trigram tokenizer (that is, it splits text into runs of three consecutive characters). exact_aliases: builds exact aliases for issue keys, file paths, symbols, graph IDs, source IDs, and titles.
FTS handles natural-language and lexical recall. Exact aliases handle cases such as ISSUE-1234, GraphQL fields, and CamelCase methods, where semantic approximation alone is not acceptable. If an exact candidate did not make the dense top-K, System Shadow asks Qdrant by point ID for its real cosine score and then adds it to the dense ranking. It does not invent a rank to make the candidate satisfy 70/30.
The keyword DB also stores parent rows. After a child hit, the parent text is hydrated through parent_id, which gives both precise location and complete reading context. The parent context does not thereby become a new, independent high-scoring piece of evidence.
Neo4j: Stores Only the Traversable Semantic Graph
The Neo4j system graph stores canonical entities, typed relations, and independent evidence:
- Nodes such as Repository, File, Class, Method, GraphQLOperation, Endpoint, Page, and Issue.
- Relations such as
CALLS,ROUTES_TO,USES_OPERATION,SELECTS_FIELD,RESOLVES_FIELD,READS, andWRITES.
It does not store raw PDFs, full HTML, embeddings, or the full CPG blob; those go back to CAS. Nor is it a vector store. The value of a graph query is finding a path from a resolved anchor, constrained by direction, a relation allowlist, a hop bound, and edge evidence.
The System Shadow query first checks the projection marker, the source manifest, and the graph cursor, then returns only paths with confidence=VERIFIED and complete evidence.
Neo4j expansion in the default external API is a different runtime path, with a configured maximum graph depth of 3; the shadow search_verified_paths call currently caps at 4 hops. Neither number is a general conclusion that “deeper graphs are better.”
Why Not Use Distributed Transactions
Qdrant, SQLite, and Neo4j cannot share one local ACID transaction. The current design uses stable IDs, the manifest, independent cursors, and idempotent upserts/deletes to achieve detectable eventual consistency, that is, stores may be briefly out of sync, but a query can tell which one lags:
Vector may update first and graph may retry later, but a query cannot stitch results from two different generations into a “verified call chain.” This strategy gives up instantaneous global transactions in exchange for store failure isolation and replayability.
Why External Callers Should Only Use the Answer API
Product code that reads Qdrant or Neo4j directly bypasses the source-type policy, the manifest gate, reranking, the citation guard, and fail-closed output (that is, no output when a check fails). The currently supported boundary is POST /v1/answer, or the streaming /v1/answer/stream.
The API can select qdrant, zvec, or pgvector, or return a comparison through compare_stores. Neo4j acts as relationship expansion through use_neo4j_graph and does not appear in the vector_store enum. A store comparison should use the same embedding and the same query set; otherwise there is no way to tell whether a difference comes from the model or from the database.
Failure Modes and Trade-offs
Each row is one store or boundary: read how it fails first, then the strategy currently used to handle it.
| Store/boundary | Failure mode | Current strategy |
|---|---|---|
| Qdrant | Collection does not match the manifest/embedder | Verify generation, hash, model, dimension, and profile before querying |
| FTS | Index corresponds to an old chunk file | Metadata stores the input SHA-256; on mismatch, rebuild or refuse to use it |
| Exact alias | Exact result is not in the dense top-K | Request its real dense score before it enters RRF |
| Neo4j | Graph projection or cursor lags | No verified path is emitted; stale is stated explicitly |
| Multiple stores | One side succeeds, the other fails | Retry on independent cursors; never masquerade as globally complete |
| Direct store access | Bypasses the guard and citations | Only the Answer API is exposed externally |
| Polyglot persistence | Deployment, monitoring, and backup are more complex | Each store can be rebuilt from CAS/manifest, and responsibilities are clearer |
Verifiable Project Evidence
config/rag-runtime.json: embedding, collection, vector store, Neo4j, and shadow configuration.src/mt_rag/retrieval/system_index.py: Qdrant payload, embedding cache, SQLite FTS/exact alias, and the manifest gate.src/mt_rag/retrieval/stores/adapters.py: the store adapter boundary.src/mt_rag/system_graph/batch.py: projection from the canonical graph into Neo4j.src/mt_rag/system_graph/query.py: the graph projection/cursor gate and verified paths.src/mt_rag/service/server.py:/v1/answer, store selection, and strict requests.docs/02-runbooks/local-llm-service.md: the current external service, ports, profiles, and API contract.
References
- Qdrant documentation on collections
- Qdrant documentation on points
- SQLite FTS5 documentation
- pgvector project
- Neo4j Cypher Manual
- Neo4j GraphRAG retriever documentation
- Qwen3 Embedding Technical Report
The clearer each store's responsibility, the easier it is to explain an answer: this part was discovered semantically, this part was hit by an exact identifier, and this relationship was proven by the graph and its evidence. No single database is granted the privilege of being “the truth.”
Related notes
Balancing 70/30 Hybrid Retrieval and the Graph Anchor
Vector, keyword, parent-child context, and verified graph paths are combined in layers so that similar content is never mistaken for proof of a call.
Where the Cost of a Model Call Comes From, and Where It Can Go Wrong
Token, Context, Prefill, Decode, and caching determine an Agent’s cost and latency; hallucination and Prompt Injection determine the floor of its risk. Without understanding these, none of the later architectural trade-offs has a basis.
Working on something similar?
I'm always happy to compare notes on distributed systems, delivery, and applied AI.
[email protected]