run-llama/llama_index · error · ValueError
Unknown query mode: {query_mode}
Error message
Unknown query mode: {query_mode} What it means
get_top_similar_embeddings_by_query only supports three classifier modes: SVM, LINEAR_REGRESSION, and LOGISTIC_REGRESSION. Passing any other VectorStoreQueryMode (DEFAULT, MMR, HYBRID, etc.) falls through to the else and raises, because the function is a specialized embedding-ranking helper, not a general query dispatcher.
Source
Thrown at llama-index-core/llama_index/core/indices/query/embedding_utils.py:86
embeddings_np = np.array(embeddings)
# create dataset
dataset_len = len(embeddings) + 1
dataset = np.concatenate([query_embedding_np[None, ...], embeddings_np])
y = np.zeros(dataset_len)
y[0] = 1
if query_mode == VectorStoreQueryMode.SVM:
# train our SVM
# TODO: make params configurable
clf = svm.LinearSVC(
class_weight="balanced", verbose=False, max_iter=10000, tol=1e-6, C=0.1
)
elif query_mode == VectorStoreQueryMode.LINEAR_REGRESSION:
clf = linear_model.LinearRegression()
elif query_mode == VectorStoreQueryMode.LOGISTIC_REGRESSION:
clf = linear_model.LogisticRegression(class_weight="balanced")
else:
raise ValueError(f"Unknown query mode: {query_mode}")
clf.fit(dataset, y) # train
# infer on whatever data you wish, e.g. the original data
similarities = clf.decision_function(dataset[1:])
sorted_ix = np.argsort(-similarities)
top_sorted_ix = sorted_ix[:similarity_top_k]
result_similarities = similarities[top_sorted_ix]
result_ids = [embedding_ids[ix] for ix in top_sorted_ix]
return result_similarities, result_ids
def get_top_k_mmr_embeddings(
query_embedding: List[float],
embeddings: List[List[float]],
similarity_fn: Optional[Callable[..., float]] = None,View on GitHub (pinned to afd0fef371)
Solutions
- Use one of VectorStoreQueryMode.SVM, .LINEAR_REGRESSION, .LOGISTIC_REGRESSION when this code path is hit
- For nearest-neighbour semantics use VectorStoreQueryMode.DEFAULT (handled by the vector store, not this helper)
- Validate query_mode against the supported set before constructing the retriever
Example fix
# before retriever = index.as_retriever(vector_store_query_mode=VectorStoreQueryMode.MMR) # if this path is entered: ValueError # after retriever = index.as_retriever(vector_store_query_mode=VectorStoreQueryMode.SVM) # or DEFAULT
Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED = {VectorStoreQueryMode.SVM, VectorStoreQueryMode.LINEAR_REGRESSION, VectorStoreQueryMode.LOGISTIC_REGRESSION}
if query_mode in SUPPORTED and not has_sklearn():
query_mode = VectorStoreQueryMode.DEFAULT
retriever = index.as_retriever(vector_store_query_mode=query_mode) Type guard
def is_classifier_mode(mode: VectorStoreQueryMode) -> bool:
return mode in {
VectorStoreQueryMode.SVM,
VectorStoreQueryMode.LINEAR_REGRESSION,
VectorStoreQueryMode.LOGISTIC_REGRESSION,
} Try / catch
try:
sims, ids = get_top_similar_embeddings_by_query(qe, embeddings, query_mode=mode)
except ValueError as e:
if 'Unknown query mode' in str(e):
raise ValueError(f'{mode} not supported here; use SVM/LINEAR_REGRESSION/LOGISTIC_REGRESSION or DEFAULT') from e
raise Prevention
- Restrict mode pickers in config/UI to modes the target engine actually supports
- Keep one mapping of mode -> engine support instead of scattering enums through configs
When it happens
Trigger: Setting vector_store_query_mode to something other than the three supported values on a retriever whose code path routes into this helper — e.g. SVM-mode embeddings but the mode string was overwritten later, or passing an unvalidated string/int as query_mode.
Common situations: Copy-pasting retriever configs between engines where the same enum value routes to different internals; building a mode selector UI that forwards arbitrary enum values; refactoring from QueryMode (old enum) to VectorStoreQueryMode and passing a stale value.
Related errors
- Max iterations of {max_iterations} reached! Either something
- CitableBlock content must contain exactly one block when pro
- Eval mode {eval_mode} not supported.
- Cannot specify both system_prompt and prefix_messages
- Cannot specify both system_prompt and prefix_messages
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/dffc5eee36b2d862.
Report an issue: GitHub.