[Bug] Beifong FAISS search: L2 distance mapped with exp(-d) breaks 85% similarity filter
Author: midasstackCreated Sep 7, 2026Updated Sep 12, 2026
Description
In the AI News and Podcast Agents (Beifong) app, semantic search over the internal article KB converts FAISS L2 distance with exp(-distance) and treats that as a cosine-style similarity score with an 85% threshold. That mapping is mathematically wrong for L2 embeddings, so almost all real semantic matches fail the filter. Perfect matches (distance == 0) are also scored as 0 and dropped.
Location
advanced_ai_agents/multi_agent_apps/ai_news_and_podcast_agents/beifong/tools/embedding_search.py (around lines 99–126)
Related: index is built as L2 in beifong/processors/faiss_indexing_processor.py (IndexFlatL2 / HNSW-L2 / IVF-L2).
Buggy code
similarity_threshold = 0.85
...
distance = float(distances[0][i])
similarity = float(np.exp(-distance)) if distance > 0 else 0
if similarity >= similarity_threshold:
...
Source: Shubhamsaboo/awesome-llm-apps