The Silent Vector Contamination Bug: Why Your Concurrent Embeddings Might Be Lying to You A developer discovered a silent race condition in OpenVINO's AsyncInferQueue that caused concurrent embedding requests to return vectors belonging to other inputs. The bug, which passed standard unit tests, was caught by a cosine-similarity contamination test that verified vector identity under high concurrency. TL;DR:If you run concurrent inference e.g., via OpenVINO AsyncInferQueue or custom threading for text/code embeddings, your tests might show 0 exceptions and 0 errors , while silently returning embeddings belonging tootherinputs in the batch. Here is how we caught a subtle race condition using a cosine-similarity contamination test. We use OpenVINO with an INT8 quantized E5-small https://huggingface.co/keisuke-miyako/multilingual-e5-small-onnx-int8 model for in-process code embedding. To maximize throughput on multi-core CPUs, we set up an asynchronous inference queue AsyncInferQueue with jobs=4 . In standard unit testing, everything looked pristine: None values or zero-filled tensors were returnedHowever, during end-to-end RAG retrieval tests, we noticed weird semantic anomalies: searching for authentication logic would occasionally return chunks related to database migrations or UI components with unreasonably high confidence. The root cause was a subtle race condition in callback/userdata mapping inside the async wrapper. Because the inputs were processed concurrently across multiple execution streams, a shared user-data context wasn't strictly isolated per inference request. When Request A auth.py and Request B payment.py were scheduled back-to-back: Standard assertion tests like assert output vector is not None or assert output vector.shape == 384, passed 100% of the time. The pipeline was silently corrupting the vector store. Before fix: shared results dict across concurrent calls self. ov results = {} def callback request, userdata : BUG: userdata is a global index 0, 1, 2, ... Two concurrent calls reuse the same indices self. ov results userdata = request.get tensor .data The problem: userdata was a simple integer counter 0, 1, 2, ... that reset between embed batch calls. When two calls overlapped, they wrote to the same dictionary keys. To catch this reliably in CI, we wrote an explicit cross-contamination test designed for concurrent embedding queues. python import asyncio import numpy as np import pytest def cosine similarity a: np.ndarray, b: np.ndarray - float: """Calculate cosine similarity between two vectors.""" return float np.dot a, b / np.linalg.norm a np.linalg.norm b @pytest.mark.asyncio async def test async embedder no cross contamination embedder : """Verify that concurrent embedding doesn't cross-contaminate vectors.""" 1. Semantically distinct inputs samples = { "auth": "def authenticate user username, password hash : return verify jwt token ", "sql": "SELECT u.id, u.email FROM users u JOIN orders o ON u.id = o.user id WHERE o.status = 'active'", "html": "