Engineering teams often assume a Retrieval-Augmented Generation (RAG) vector store is safe if the retrieval endpoint omits raw document text. When multiple tenants share one unpartitioned index and the API returns exact cosine similarity floats with no query budget, the similarity scores alone reconstruct the restricted record.
Embedding Inversion Lab builds a paired vulnerable-and-fixed vector store in Python stdlib and sqlite3 (github.com/ghostintheprompt/embedding_inversion_lab), indexing public engineering docs (public_eng) next to restricted HR and security records (hr_restricted, sec_restricted).
Reconstructing a restricted record from similarity scores alone
In vulnerable/store.py, every row in chunks is scored regardless of caller_tenant (CWE-284, OWASP LLM02). A public_eng caller querying compensation terms pulls hr-01 straight into the result set.
Disabling raw text (include_text=False) does not close the leak. By sweeping 26 single-word probes across the index (CWE-200, OWASP LLM08, MITRE ATLAS AML.T0044), an unprivileged caller observes exact cosine spikes (score >= 0.25) on every vocabulary token present inside hr-01, recovering 88.89% of the restricted document's words without reading a character of body text. Probing a single synthetic identifier (000-00-4219) confirms membership in one call (AML.T0024).
Partitioning before ranking and capping the session budget
Post-filtering unauthorized rows after computing top_k still leaks side-channel count signals and starves legitimate results. fixed/store.py enforces tenant isolation inside SQL before a single cosine product runs:
rows = self.conn.execute(
"SELECT doc_id, tenant, sensitivity, text, embedding FROM chunks WHERE tenant = ?",
(caller_tenant,),
).fetchall()
To harden intra-tenant retrieval against score-oracle probing, fixed/store.py quantizes vectors to four levels, adds bounded deterministic perturbation before bucketing scores into 0.25 steps, caps top_k at two, and enforces an eight-query session budget (PermissionError: query_budget_exceeded). In detect/rule.py, three JSONL rules (VEC-001 single-token sweep, VEC-002 budget exhaustion, and VEC-003 over-broad top_k > 3) flag probing runs with zero false positives on normal multi-word searches.
Measuring reconstruction before and after the fix
Running make test verifies public retrieval parity across both stores and measures token recovery across all three attack paths:
Metric | Vulnerable | Fixed
----------------------------------------------------------------
Cross-Tenant Retrieval | True | False
Score-Only Token Recovery | 88.89% | 0.00%
SSN Membership Inference | True | False
Queries Executed | 26 | 8
Ran 4 tests in 0.004s (OK)
This benchmark uses a deterministic normalized bag-of-vocabulary embedding rather than a 1,536-dimensional neural encoder. Dense transformer embeddings require surrogate-model or gradient inversion (Vec2Text-style iterative recovery) rather than single-word sweeps, while relying on the same pre-ranking tenant partition and query-budget controls to stop oracle access.
GhostInThePrompt.com // Filter the tenant before you score the vector.