{"slug": "why-vector-search-breaks-production-building-a-2-hop-relational-context-engine", "title": "Why Vector Search Breaks Production: Building a 2-Hop Relational Context Engine in Sanity", "summary": "A developer built SHIPCHECK, a deterministic 2-hop relational context engine on the Sanity Content Lake, to replace vector similarity search for engineering dependency queries. Benchmarked against a simulated Pinecone/LangChain RAG pipeline over the same 18 documents, the vector approach returned a false \"SAFE TO SHIP\" verdict and missed a Payment SDK version requirement, while the GROQ-based graph traversal detected the cluster collision and returned a hard blocker. The engine also resolves documentation drift by authority level and supports in-memory graph mutation for simulating fixes.", "body_md": "*This is a submission for the [Sanity Challenge, Path Two: Build a Knowledge Base or Context Engine](https://dev.to/challenges/sanity-2026-09-16).*\n\nThe 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.\n\n**For engineering infrastructure, vector search is a recipe for outages.**\n\nVector databases compress text into high-dimensional vectors. In doing so, they lose:\n\n`Service A v4` strictly requires `Service B >= v3.0`.\nFor **Path Two**, we built a **deterministic 2-hop relational context engine** on top of the **Sanity Content Lake**. Instead of flattening our documentation into vectors, we model organizational knowledge as a structured, queryable graph of microservices, version constraints, policies, and semantic relationships.\n\nWhen an engineer or autonomous coding assistant asks:\n\n*\"Can I upgrade payment service from v2 to v4 tonight?\"*\n\nOur engine doesn't guess with embeddings. It executes deterministic GROQ graph traversals that surface the hidden dependency chain, detect cluster pod collisions, and resolve documentation contradictions with 100% mathematical precision.\n\nWe designed 18 interconnected documents in Sanity (`70rd1u6b`) across three core schema types:\n\n`component`` versionConstraint``targetComponent`, `requiredComponent`, `operator`, `version`, `criticality`).` knowledgeEntry``contradicts`: Directed references pointing to documents this entry intentionally overrides.`isExceptionOf`: Encodes conditional policy exemptions (e.g., emergency security hotfixes).`authorityLevel`: An integer (1–10) providing deterministic arbitration when documentation drifts.\nHere is the core GROQ query executed by our context engine to resolve 2-hop dependency chains in a single database round-trip:\n\n```\n*[_type == \"component\" && name == $componentName][0] {\n  name,\n  currentVersion,\n  \"hop1_constraints\": *[_type == \"versionConstraint\" && targetComponent._ref == ^._id] {\n    \"requiredServiceName\": requiredComponent->name,\n    \"requiredClusterVersion\": requiredComponent->currentVersion,\n    operator,\n    version,\n    criticality\n  },\n  \"drift_audit\": *[_type == \"knowledgeEntry\" && references(^._id)] | order(authorityLevel desc) {\n    title,\n    authorityLevel,\n    sourceType,\n    \"contradicts\": contradicts[]->title,\n    \"isExceptionOf\": isExceptionOf->title,\n    body\n  }\n}\n```\n\nThis single query traverses:\n\n`Payment Service`).` requires Payment SDK >= v3.0.0`).` Payment SDK v2.4.1`).\nWe benchmarked our Sanity Context Engine against a standard vector similarity search (simulating Pinecone / LangChain RAG) over the exact same 18 documents.\n\n**User Query:** *\"Can I upgrade payment service from v2 to v4 tonight?\"*\n\n| Evaluation Metric | Naive Vector Search (Pinecone/RAG) | SHIPCHECK Sanity Context Engine | \n|---|---|---|\n| **Verdict** | ❌ `SAFE TO SHIP`*(False Positive)* | ✅ `DO NOT SHIP YET`*(Hard Blocker)* | \n| **Why it reached this result** | Matched keywords \"payment service\" and \"upgrade\". Found documents saying v4 has great new features. Completely missed the SDK requirement because the word \"SDK\" was not in the prompt. | Traversed Hop-1 to find `Payment SDK >= v3.0.0` . Traversed Hop-2 to find cluster running`v2.4.1` . Detected collision immediately. | \n| **Documentation Drift** | Hallucinated a merge of XML and JSON specs. | Resolved by authority: Release Notes (Auth 10) explicitly supersedes Stale Wiki (Auth 4). | \n| **Production Outcome** | **P0 Outage:** Token HMAC verification failures across all checkout pods. | **0 Outages:** Outage prevented before code merged. | \n\nOur engine supports **in-memory graph mutation**. When an engineer clicks *\"Simulate Fix\"*, the engine re-evaluates the GROQ traversal with `Payment SDK v3.1.0` applied to the cluster representation. The 2-hop collision clears, all constraints evaluate to green, and the verdict live-flips to `SAFE TO SHIP`.\n\n`lib/engine/groqTraversal.ts`` sanity/schemaTypes/``lib/engine/naiveSearchStub.ts`\nWhen building this context engine for AI coding assistants (via MCP JSON-RPC), we noticed:\n\n`70rd1u6b`\n`production`\n`2024-01-01`\n*Built with ❤️ for the Sanity Context MCP Hackathon (Path Two).*", "url": "https://wpnews.pro/news/why-vector-search-breaks-production-building-a-2-hop-relational-context-engine", "canonical_source": "https://dev.to/rajan_mishra_a9f78ad216b4/why-vector-search-breaks-production-building-a-2-hop-relational-context-engine-in-sanity-134c", "published_at": "2026-09-26 00:09:19+00:00", "updated_at": "2026-09-26 00:30:43.587445+00:00", "lang": "en", "topics": ["ai-agents", "ai-infrastructure", "structured-data", "developer-tools", "ai-tools"], "entities": ["Sanity", "Sanity Content Lake", "SHIPCHECK", "GROQ", "Pinecone", "LangChain", "Chroma", "pgvector"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/why-vector-search-breaks-production-building-a-2-hop-relational-context-engine", "markdown": "https://wpnews.pro/news/why-vector-search-breaks-production-building-a-2-hop-relational-context-engine.md", "text": "https://wpnews.pro/news/why-vector-search-breaks-production-building-a-2-hop-relational-context-engine.txt", "jsonld": "https://wpnews.pro/news/why-vector-search-breaks-production-building-a-2-hop-relational-context-engine.jsonld"}}