steep-thailand-10741
02/03/2026, 5:27 PMpython
# English entry
{
"embedding": [0.23, 0.45, ...],
"metadata": {
"question": "what are the best restaurants?",
"answer": "The best restaurants are: Trattoria Roma, Pizzeria Napoli...",
"language": "en"
}
}
# Italian entry
{
"embedding": [0.24, 0.46, ...],
"metadata": {
"question": "quali sono i migliori ristoranti?",
"answer": "I migliori ristoranti sono: Trattoria Roma, Pizzeria Napoli...",
"language": "it"
}
}
## The Problem
Since embeddings are semantic, "best restaurants" (English) and "migliori ristoranti" (Italian) have very similar vectors. Without proper filtering, an Italian user asking "ristoranti" might get the cached English response.
My current approach: Filter vector search by language metadata:
python
results = vector_db.query(
embedding=embed(user_message),
filter={"language": user_language},
top_k=1
)
This works IF I can reliably detect the user's language. But:
- Messages are often very short ("museums", "metro", "parking")
- Language detection libraries (langdetect, fastText) are unreliable with < 20 characters
- The chatbot is stateless (no conversation history for caching efficiency)
- Platform is WhatsApp (no browser headers available)mammoth-lighter-94680
02/03/2026, 6:28 PMsteep-thailand-10741
02/03/2026, 11:56 PMmammoth-lighter-94680
02/04/2026, 3:07 PM