microsoft/graphrag · error · ValueError
Query and document embeddings are not compatible. Please ens
Error message
Query and document embeddings are not compatible. Please ensure that the embeddings are of the same type and length.
What it means
DRIFT search compares the embedding of the user query against the full_content_embedding column of the community reports using cosine similarity, and first verifies the two vectors are compatible (same dimensionality/type). If the query embedder produces vectors of a different dimension or dtype than the report embeddings stored in the index, this ValueError is raised.
Source
Thrown at packages/graphrag/graphrag/query/structured_search/drift_search/drift_context.py:214
chat_model=self.model,
text_embedder=self.text_embedder,
tokenizer=self.tokenizer,
reports=self.reports,
)
query_embedding, token_ct = await query_processor(query)
report_df = self.convert_reports_to_df(self.reports)
# Check compatibility between query embedding and document embeddings
if not self.check_query_doc_encodings(
query_embedding, report_df["full_content_embedding"].iloc[0]
):
error_message = (
"Query and document embeddings are not compatible. "
"Please ensure that the embeddings are of the same type and length."
)
raise ValueError(error_message)
# Vectorized cosine similarity computation
query_norm = np.linalg.norm(query_embedding)
document_norms = np.linalg.norm(
report_df["full_content_embedding"].to_list(), axis=1
)
dot_products = np.dot(
np.vstack(report_df["full_content_embedding"].to_list()), query_embedding
)
report_df["similarity"] = dot_products / (document_norms * query_norm)
# Sort by similarity and select top-k
top_k = report_df.nlargest(self.config.drift_k_followups, "similarity")
return top_k.loc[:, ["short_id", "community_id", "full_content"]], token_ct
View on GitHub (pinned to f40e9a26ce)
Solutions
- Use the same embedding model (same dimensions) for querying as was used to build the index
- Re-index the data with the new embedding model if you intend to switch models
- Inspect report_df['full_content_embedding'] for empty/NaN vectors and drop or regenerate those rows
- Confirm your settings.yaml text_embedder configuration matches the index's model
Example fix
# before context = DriftContext(text_embedder=OpenAIEmbedding(model="text-embedding-3-large"), ...) # index used ada-002 # after context = DriftContext(text_embedder=OpenAIEmbedding(model="text-embedding-ada-002"), ...) # match index model
Defensive patterns
Strategy: validation
Validate before calling
query_emb = text_embedder("test")
report_emb = report_df["full_content_embedding"].iloc[0]
if len(query_emb) != len(report_emb):
raise ValueError(
f"Embedding dims differ: query={len(query_emb)}, reports={len(report_emb)}. "
"Use the same embedding model as indexing or re-index."
) Type guard
def embeddings_compatible(q, d) -> bool:
import numpy as np
q, d = np.asarray(q), np.asarray(d)
return q.ndim == 1 and d.ndim == 1 and q.shape[0] == d.shape[0] and np.isfinite(q).all() and np.isfinite(d).all() Prevention
- Pin the same embedding model in settings.yaml for both indexing and querying
- Store the embedding model name/dims as metadata alongside the index and check it at query time
- After loading reports, drop rows with NaN/None in full_content_embedding
When it happens
Trigger: Calling DriftSearch.search with text_embedder configured for a different model than the one used at indexing time (e.g. index built with text-embedding-ada-002 of 1536 dims, query uses a 3072-dim model), or when full_content_embedding in the report DataFrame is empty/malformed.
Common situations: Switching embedding models or API tiers between indexing and querying, changing the embedding model in settings.yaml after the index was built, using a custom LocalSearch mixed context with mismatched vector lengths, or NaN/None embeddings in the parquet file.
Related errors
- No community reports available. Please provide a list of rep
- No intermediate answers found in primer response. Ensure tha
- No follow-up queries found in primer response. Ensure that t
- Response must be a list of dictionaries.
- DRIFT Search query cannot be empty.
AI-assisted analysis of microsoft/graphrag@f40e9a26ce (2026-08-27).
Data as JSON: /api/errors/be4bbee4aca70fe6.
Report an issue: GitHub.