Vector search without top-k cap

ID

vector-search-without-top-k-cap

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

OWASP LLM

LLM10:2025 — Unbounded Consumption

Family

LLM10 — Unbounded Consumption

Red-team vectors

(none — LLM10 carries no red-team vector)

Tags

ai_security

Description

A raw vector-search / retrieval call runs with no top_k / k / result-size bound and no framework default in effect. An unbounded result set flows into the prompt and drives runaway token consumption downstream.

Framework-default aware: LangChain similarity_search(…​) and as_retriever(…​) default k=4 and are not flagged (their default is encoded); only raw index queries (index.query(…​), collection.search(…​)) with no explicit bound fire.

Examples

results = index.query(vector=vec)   (1)
1 Raw index query with no top_k — flagged (low).

An explicit top_k=5, or a LangChain store.similarity_search(query) (default k), produces no finding.

Mitigation / Fix

  • Set an explicit top_k / k / result-size limit on the retrieval call.

  • Bound the retrieved context so downstream token usage is predictable.