跳到正文
DEV Community· Shivam Dwivedi·· 52 分鐘前AI 評分56

語音智能體找到段落後,如何確認是否找對資料?

Your voice agent found passages. Did it find the right ones?

AI 導讀

Shivam Dwivedi 提供一段可執行的 Python 程式,以 recall@k 檢查檢索結果是否包含已標註的相關段落,而非只看結果清單是否非空。文中的虛構例子中,英文、Hindi、Telugu 的 recall@k 分別為 50%、0%、100%,宏平均為 50%,合併匹配段落計算則為 40%。

正文

A retrieval call can return a full list of passages and still leave a voice assistant with nothing useful to say. The request succeeded. The evidence failed.

IBM Research's new CUGA voice-agent write-up describes exactly that failure: regional-language questions were being searched against an English handbook with an English-only embedding model. The system returned passages, but the relevant evidence was missing. Its grounded answer then declined to help. The authors report switching to intfloat/multilingual-e5-large. [1]

I want a retrieval check before adding speech. Otherwise a pleasant voice can make a broken search sound very convincing.

A full result list earns no points by itself

Here is an invented retrieval fixture. en, hi and te label intended English, Hindi and Telugu test groups. The IDs stand for chunks in a tiny imaginary document. There are no embeddings, translations or model calls in this example.

Three synthetic query rows all return two chunks; relevant chunks are one of two, zero of two and one of one. Macro recall is 50%.

Original diagram of the fixture below. Filled result slots and relevant evidence are different quantities.

For a query with a known set of relevant chunks, recall at k is:

distinct relevant IDs in the first k results / all known relevant IDs

The denominator comes from the answer key, not the result-list length. A query needing two chunks receives only half credit when one appears, even if the application asked for two results and got two back.

Save this as retrieval_check.py and run python3 retrieval_check.py. It uses Python's standard library.

from fractions import Fraction
def recall_at_k(gold, ranked, k):
    if not gold or k < 1:
        raise ValueError("Need relevant IDs and a positive k")
    return Fraction(len(gold & set(ranked[:k])), len(gold))
gold = {"en": {"a", "b"}, "hi": {"a", "b"}, "te": {"c"}}
ranked = {"en": ["a", "x"], "hi": ["x", "y"], "te": ["c", "z"]}
scores = []
for language in gold:
    score = recall_at_k(gold[language], ranked[language], 2)
    scores.append(score)
    print(language, len(ranked[language]), f"{float(score):.0%}")
print("macro recall", f"{float(sum(scores) / len(scores)):.0%}")

The checked output is:

en 2 50%
hi 2 0%
te 2 100%
macro recall 50%

All rows are equally full. Their usefulness is rather less equal. 🔎

set(ranked[:k]) prevents a duplicate chunk from earning credit twice. Empty relevance labels are rejected because recall would have no denominator. In a real dataset, unanswerable questions need a separate abstention test; quietly treating them as perfect retrieval would inflate this score.

The macro average gives each query equal weight. Here it is (1/2 + 0 + 1)/3 = 1/2. Pooling the matching chunks instead gives 2/5, or 40%, because the queries have different numbers of relevant chunks. Choose the aggregation deliberately and retain the per-language rows.

Connect the check to real retrieval

Replace the invented ranked IDs with your search output. Keep the question ID, requested language, corpus revision and returned chunk IDs together. Have a qualified reader label the needed evidence before examining which model looks best. That turns a disappointing answer into a traceable question: was the needed passage available to the answer generator?

Changing the embedding model also has a formatting contract. E5's model card specifies query: for queries and passage: for documents, including non-English inputs. It also documents pooling and normalization. A multilingual model name alone doesn't verify those details. [2]

I would test text queries before introducing transcription, then compare the recognized text with the intended question. Those checks isolate retrieval failure from speech recognition failure. An answer can still misuse good evidence, so answer correctness needs its own check after retrieval passes.

This program tests metric bookkeeping on hand-written rankings. Its language labels do not measure language quality, and it does not reproduce IBM's application. The useful result is a runnable check that refuses to mistake a nonempty list for successful retrieval.

References

  1. IBM Research — An Indic Voice Agent with CUGA
  2. Multilingual E5 large — model card and retrieval input format
  3. Python — fractions

Asset credits

Original fixture diagram, released under CC BY 4.0. Credit: Shivam Dwivedi.

AI disclosure

AI was used to draft the article.

來源:DEV Community · dev.to