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)加速,此時必須保證向量已歸一化,否則內積會被模長帶偏。