Why Vector Search Breaks Production: Building a 2-Hop Relational Context Engine in Sanity
This is a submission for the Sanity Challenge, Path Two: Build a Knowledge Base or Context Engine . What I Built The AI community has spent the last three years building Retrieval-Augmented Generation (RAG) on top of vector similarity search (Pinecone, Chroma, pgvector). For prose and chat applications, cosine similarity on text chunks works well. For engineering infrastructure, vector search is…
The AI community has been developing Retrieval-Augmented Generation (RAG) using vector similarity search techniques like Pinecone, Chroma, and pgvector for prose and chat applications. However, when applied to engineering infrastructure, vector search can lead to outages due to the loss of relational constraints, authority hierarchies, and multi-hop transitivity during the compression of text into high-dimensional vectors.
To address these issues, the Sanity team built a 2-hop relational context engine on top of Sanity Content Lake, which models organizational knowledge as a structured graph of microservices, version constraints, policies, and semantic relationships. This engine executes deterministic GROQ graph traversals to surface hidden dependency chains and resolve documentation contradictions with mathematical precision.
The Sanity team used Sanity to create 18 interconnected documents across three core schema types: Schema Graph, versionConstraint, and knowledgeEntry. The core GROQ query used by the context engine traverses three hops to resolve 2-hop dependency chains in a single database round-trip. The engine first identifies the target component, then the relational version constraint, and finally the active cluster state of the required dependency.
Authority resolution is handled by sorting conflicting specs by authorityLevel so the newest specification always wins.
In a live benchmark, the Sanity Context Engine was compared to a standard vector similarity search. The engine correctly detected a P0 outage caused by a version constraint mismatch between payment service and its SDK dependency, while the vector search failed to identify the issue. The Sanity Context Engine also supports in-memory graph mutation, allowing engineers to simulate fixes and immediately see the impact on constraints and overall document reliability.
This approach eliminates false positives and provides a more accurate, structured, and explainable context for AI coding assistants.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.