concept

Exact and approximate retrieval

Local exact squared-L2 top-k oracle and ANN result overlap. Compare on a consistent eligible snapshot and tie convention; empty baseline is undefined.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
exact_top_k(query, rows, k); index_recall(exact, returned)

Working Example

Example Snippetartificial-intelligence
def exact_top_k(query, rows, k):    # Small integer vectors; squared L2 distance; stable string IDs.    if not query or type(k) is not int or k < 1:        raise ValueError("nonempty query and positive k required")    if any(type(x) is not int for x in query):        raise ValueError("integer coordinates required")    seen = set()    scores = []    for key, vector in rows:        if not isinstance(key, str) or not key or key in seen:            raise ValueError("unique nonempty IDs required")        if len(vector) != len(query) or any(type(x) is not int for x in vector):            raise ValueError("incompatible vector")        seen.add(key)        distance = sum((x-y)**2 for x, y in zip(query, vector))        scores.append((distance, key))    return [key for _, key in sorted(scores)[:k]]
rows = [("a", [1, 0]), ("b", [0, 1]), ("c", [2, 0]),        ("d", [3, 3]), ("e", [-2, 0])]print(exact_top_k([0, 0], rows, 2))