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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Vector search can find Sanity documents that are conceptually relevant, but similarity alone cannot enforce exact requirements or explain how a result connects to other records. A practical two-hop design combines structured filtering and semantic ranking to find candidates, then uses GROQ references or bounded subqueries to retrieve only the related context the application needs.

Why vector search can fail to meet production requirements

Semantic similarity is a ranking signal, not a guarantee that a result satisfies a hard condition. A document can be conceptually close to a query while having the wrong content type, status, tenant, or access eligibility. Treating the similarity score as a probability—or assuming a particular numeric score means the same thing across different queries—can also lead to brittle decisions.

There is a second limitation: an embedding projection covers content in the document itself. It does not automatically bring in referenced documents or other relational context. A highly relevant candidate may therefore be incomplete for a task that needs its parent, related product, author, or other connected record.

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.

These are design constraints, not evidence that vector search always fails or that one retrieval pattern universally outperforms another. Sanity’s documentation describes the available mechanisms and operational considerations, but does not establish a general production failure rate or a benchmark for two-hop retrieval.

What “two-hop” retrieval means in Sanity

Think of the workflow as two distinct stages:

  1. Find candidates: apply the exact eligibility filters the application requires, then rank eligible documents using semantic similarity, keyword relevance, or both.
  2. Expand context: for the selected candidates, follow modeled references or run bounded GROQ subqueries to retrieve related records and the specific fields needed downstream.

The first hop answers “Which documents might be relevant?” The second answers “What connected information is needed to use those documents?” Keeping those jobs separate makes it easier to reason about eligibility, relevance, and context completeness.

Build the first hop: filter, then rank

Enforce hard requirements with structured filters

Put exact requirements—such as document type, publication status, tenant, or permissions—in the eligibility logic, rather than expecting similarity ranking to enforce them. Confirm that the filter is supported by the query shape and correctly reflects the application’s access model. A filter in a retrieval query is not a substitute for a sound authorization design.

Sanity documents text::semanticSimilarity() as a scoring function, and states: “The text::semanticSimilarity() function is only valid as an argument to score().” See Sanity’s context retrieval modes documentation (last updated September 3, 2026). Use the score to order eligible candidates, not as a calibrated probability or a universal cutoff.

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

Combine semantic and keyword relevance when both matter

Semantic matching can help when the user describes an idea without using the document’s exact terminology. Keyword matching remains useful for exact terms, names, and identifiers. Sanity’s GROQ search guide demonstrates combining token matching, BM25 scoring, semantic similarity, boosts, recency weighting, ordering, and pagination in one hybrid query. The appropriate mix depends on the content and the task; validate it against representative queries rather than assuming one ranking formula fits every collection.

See Sanity’s GROQ content search documentation (last updated August 6, 2026) for the documented search mechanisms.

Build the second hop: retrieve connected context

Model genuine relationships with references

When a relationship is meaningful in the domain or editorial model, represent it explicitly with a Sanity reference. GROQ can dereference a reference with ->, allowing a candidate document to bring in a related record during query-time projection. Strong references are indexed and queryable from both sides, and Sanity says referential integrity prevents deleting a referenced document. Weak references can point to missing documents and surface warnings in Studio.

References are not the only option. GROQ’s references() function and parent-scope subqueries support other relationship queries, including finding incoming references. GROQ does not support natural joins as traditionally defined; use the reference and query patterns its specification provides. See Sanity’s GROQ joins specification (last updated June 24, 2026) and its connected content documentation (accessed October 7, 2026).

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 expansion bounded and projections lean

Retrieve only the related records and fields the interface or model actually needs. Dereferencing is a subquery, so repeating the same dereference in multiple projection fields can repeat work. Where possible, compute a related object once and reuse it in the projection. This is a query-shape consideration, not a rule that every join is slow.

Sanity notes that some GROQ expressions cannot be optimized and require documents to be loaded before filtering. Inspect the actual filters and projections in your query, and measure them with representative content. Its high-performance GROQ guidance (last updated September 22, 2026) explains optimization considerations.

Choose a retrieval mode for the shape of your data

Approach Useful when Key consideration
GROQ structured retrieval Your schema and exact constraints make it clear where relevant records are. Use structured filters and modeled relationships; semantic discovery may not be needed.
Dataset embeddings with GROQ Your structured records contain prose, and users may not know the exact words to search. Embeddings can help discover candidates while GROQ filters and joins retain exact constraints and connected context.
Knowledge Base retrieval Finding relevant information across source material is the difficult part. Consider how source configuration, freshness needs, and operational complexity fit the application.

Sanity’s Context documentation says an MCP endpoint’s source configuration determines its retrieval mode. If both dataset and Knowledge Base sources are attached, the dataset source takes precedence and Knowledge Base sources are ignored. Verify the current configuration behavior before relying on a particular combination. See Sanity’s context retrieval modes documentation.

These approaches are not interchangeable on a single axis. Decide based on data shape, the need for hard filtering, where authoritative relationships live, freshness expectations, query and write performance, operational complexity, and quota model. Dataset embeddings can bridge prose and structured records; they do not replace structured filters or query-time relationship retrieval.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Design dataset embeddings for useful, maintainable search

Dataset embeddings are enabled per dataset. When enabled, Sanity computes embeddings asynchronously for existing documents, and later updates are also asynchronous. Sanity says update lag is normally under one minute, but may be longer depending on dataset size and update frequency; that is documented typical behavior, not a service-level guarantee.

Choose a targeted projection of fields users actually search. Projection scope affects embedding size, generation time, query efficiency, and relevance. Noisy fields or fields that change frequently without adding search value can make the embedding less useful and increase operational work. Projections cannot expand references, so obtain relational context separately through GROQ joins or another deliberately designed process.

The current documentation states a maximum of 10 chunks per document for embeddings, subject to change; later chunks beyond that limit are dropped from search. Sanity manages the embedding model and says it may update the model, after which the dataset is automatically recomputed. Embedding generation and updates are included at no additional cost according to the current documentation, while semantic-similarity queries count against an organization’s monthly quota. Check current plan quotas and overage rates before deployment.

Embedding work can slow writes depending on system load, and Sanity may apply rate limits; these behaviors are subject to change. Disabling embeddings may immediately delete computed embedding data, and enabling them again triggers a full recomputation. Treat disabling as destructive rather than as a harmless pause. See Sanity’s dataset embeddings documentation (last updated August 21, 2026) for current operational details.

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

Evaluate the complete retrieval path

Test the query that the application will actually run: eligibility filters, ranking, expansion, projection, and pagination together. A candidate list that looks relevant is not enough if the second hop omits a needed relationship or returns too much context.

  • Relevance: Are useful documents found for both exact-term and conceptual queries?
  • Eligibility: Are documents outside the required type, status, tenant, or access scope excluded?
  • Context completeness: Do candidates resolve to the related records needed for the task, including cases where optional or weak references are missing?
  • Freshness: How does the application behave while embedding generation or recomputation is still pending?
  • Latency and query efficiency: Measure representative query and projection shapes, including dereferences and subqueries.
  • Content extremes: Test long documents and frequently updated content, including the effects of the documented chunk limit.
  • Operations: Account for write effects, rate limits, recomputation, and the applicable query quota.

Use a representative dataset and a set of real task queries, and inspect both result quality and query behavior. Sanity’s official documentation does not provide an independent benchmark or universal relevance, latency, or completeness threshold for this architecture, so set acceptance criteria for your own application.

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.