Compute cosine similarity between a query vector and document vectors and rank the hits. Handy for RAG pipelines, semantic search and embedding debugging.
📐 计算公式 / 原理
cos(q, d) = (q·d)/(‖q‖·‖d‖),检索取 top-k 最大者
稠密检索的标准打分:查询向量与文档向量做点积后各自归一化,等价于夹角余弦。实际系统常用内积近似加 ANN 索引(HNSW/IVF)加速,此时必须保证向量已归一化,否则内积会被模长带偏。