Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk6 min

Why Vector Search Breaks in Production: Building a Two-Hop Relational Context Engine in Sanity

A production-ready Sanity search design combines exact GROQ filters with semantic ranking, then retrieves only the relational context each result needs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Vector search is good at finding documents that mean something similar; it does not guarantee that results satisfy exact requirements or include the relationships an application needs. In Sanity, a sturdier pattern is to filter eligible documents with GROQ, rank them semantically, then expand only the relevant connected context through references or bounded subqueries. This two-hop design makes retrieval more useful, but it is not a universal fix for production search: query shape, embedding freshness, content modeling, and evaluation still matter.

Why semantic search can disappoint in production

A semantic score is a ranking signal, not a hard constraint or a calibrated probability. A document can be conceptually close to a query and still be the wrong type, belong to the wrong tenant, have the wrong status, or lack a required relationship. Those requirements should be expressed as structured filters, not left to similarity ranking.

As an Amazon Associate I earn from qualifying purchases.

Sanity documents text::semanticSimilarity() as a scoring function that is valid only as an argument to score(). In practice, filter the eligible documents first, then use semantic similarity to order candidates. Do not interpret the returned number as a probability or compare scores across unrelated queries as though they share a calibrated scale. See Sanity’s context retrieval modes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a two-hop relational context engine does

Think of retrieval as two bounded stages. The first hop finds candidate documents using exact eligibility rules and semantic or hybrid ranking. The second hop adds the connected records needed to answer the request: for example, a product’s category and compatibility notes, or an article’s author and referenced policy. GROQ supports dereferencing with ->, parent-scope subqueries, and references() for other relationship patterns, including incoming references.

  1. Find candidates. Apply hard requirements such as document type, publication status, tenant, or access constraints before ranking. Enforce authorization in the application’s access model as well; a search filter should not be treated as a substitute for security controls.
  2. Rank for meaning and wording. Use semantic similarity where people may express an idea differently from the stored text. Combine it with keyword matching where exact names, identifiers, or phrases matter.
  3. Expand only necessary relationships. From the candidate set, dereference modeled relationships or run bounded subqueries to retrieve the connected records required by the task.
  4. Project a small useful result. Return only the fields the interface or downstream model needs. This controls payload size and avoids fetching unrelated content.

Sanity’s GROQ search guide shows a hybrid query combining token matching, BM25 scoring, semantic similarity, boosts, recency weighting, ordering, and pagination. That gives teams a way to balance exact terminology with conceptual matches rather than treating vector search as the only retrieval mechanism: Search your Sanity content with GROQ.

Model relationships before trying to retrieve them

The second hop is only as dependable as the relationships in the content model. Use explicit references when a connection is real and meaningful to editors or the domain, such as an article referencing a policy or a product belonging to a category. GROQ can follow those references or find documents that reference a target, but it cannot infer an authoritative relationship that was never modeled.

Sanity distinguishes strong and weak references. Strong references are indexed and queryable from both sides, and referential integrity prevents deletion of a referenced document. Weak references can point to missing documents, so Studio can surface warnings when a target is absent. Choose based on whether the target must remain present for the relationship to be valid. See Connected content and GROQ joins.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

GROQ does not provide traditional SQL-style natural joins; its relationships are expressed through references, dereferencing, and query expressions. A dereference is a subquery. Repeating the same dereference in multiple projection fields may repeat work, so retrieve a related object once and reuse that projected value where possible. This is a query-shape concern, not evidence that every join is slow.

Choose the retrieval mode to fit the data

Approach Best fit Trade-off to assess
Structured GROQ retrieval Data with useful schemas and exact constraints that tell the system where to look. Works well when the relevant fields and relationships are modeled; it cannot make vague or absent structure precise.
Dataset embeddings with GROQ Prose-rich structured records where users may not know the exact words, while filters and relationships still matter. Embedding scope, asynchronous updates, write impact, query quotas, and query shape require operational attention.
Knowledge Base retrieval Cases where the difficult step is locating relevant knowledge across source material. Choose it for that retrieval problem rather than assuming it replaces structured filters or authoritative dataset relationships.

Sanity’s Context documentation describes these modes and notes that an MCP endpoint’s source configuration determines retrieval behavior. If both dataset and Knowledge Base sources are attached, the dataset source takes precedence and Knowledge Base sources are ignored; verify current configuration behavior before relying on a mixed setup. For structured records, semantic retrieval can bridge the gap between prose and exact schema fields, but semantic ranking still does not replace filtering. See Context retrieval modes.

Design dataset embeddings around the actual search task

Dataset embeddings are enabled per dataset. Sanity computes embeddings for existing documents after enablement, asynchronously, and generates or recomputes embeddings after later document changes. The documentation says update lag is normally under one minute but can be longer depending on dataset size and update frequency; that is typical documented behavior, not a service-level guarantee. If a workflow needs stronger freshness, design for a short period in which a recently changed document may not yet be represented by its latest embedding. See Dataset Embeddings.

Keep the projection focused

Select fields users actually search. A projection that includes useful titles, descriptions, and relevant body text is more likely to produce meaningful embeddings than one that indiscriminately includes every field. Projection scope affects embedding size, generation time, query efficiency, and relevance. Avoid noisy or frequently changing fields unless they add genuine search value.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An embedding projection covers content in the document itself; it cannot expand references. Retrieve relational context at query time through GROQ joins or design a separate process if precomputed connected text is genuinely needed.

Account for chunk limits and write behavior

The current Sanity documentation states a maximum of 10 chunks per document for embeddings, subject to change; later chunks beyond that limit are dropped from search. Long documents therefore need particular attention to which content appears early and how the projection is shaped.

Embedding generation can slow writes depending on system load, and Sanity may apply rate limits; both behaviors are documented as subject to change. Sanity manages the embedding model and says the dataset is automatically recomputed when that model changes. Disabling embeddings may immediately delete computed embedding data, and enabling them again triggers a full recomputation, so treat disablement as a destructive operational decision rather than a reversible toggle without consequences.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep production GROQ queries measurable

Query cost and latency depend on the specific expressions, filters, projections, dataset, and content. Sanity notes that some expressions cannot be optimized and require loading documents before filtering. Inspect the actual query rather than assuming that all filtering or all reference traversal has the same cost. The High-performance GROQ guidance explains optimization considerations.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Keep candidate filters selective and confirm the expression is supported and enforced as intended.
  • Bound relational expansion so a candidate does not pull an unlimited graph of connected records.
  • Project only useful fields and avoid repeating identical dereferences.
  • Measure with representative content, including long documents and frequently updated records.
  • Track relevance, latency, result completeness, freshness, and behavior at realistic dataset size.

Official documentation describes mechanisms and constraints, but does not establish a universal two-hop performance advantage, failure rate, or benchmark threshold. Evaluate against your own queries and data rather than adopting a generic pass/fail number.

Evaluate the system as a retrieval pipeline

Test cases should separate failure types. If the right document is absent from the candidate set, examine the embedding projection, lexical matching, and filters. If a good candidate appears but the answer lacks a connected policy or parent record, inspect reference modeling and the second-hop query. If a recently edited record appears with old content, account for asynchronous embedding recomputation. If results are slow or incomplete, profile the exact GROQ expressions, repeated dereferences, payload size, and pagination.

Include queries that use synonyms, exact identifiers, ambiguous wording, and hard constraints such as status or tenant. Check whether the top candidates are relevant and eligible, whether the expanded records are the right ones, and whether the final projected context contains enough information without unrelated material. This diagnoses which stage needs improvement instead of treating every miss as a vector-search problem.

Plan and quota considerations

Sanity’s current documentation says embedding generation and updates are included at no additional cost, while semantic-similarity queries count against an organization’s monthly quota. Quotas and overage rates can depend on the current plan and may change, so verify the applicable terms for the organization before deploying at scale. Avoid assuming that embedding generation being included means query volume is unlimited.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.