直接暴力计算你的嵌入。
Just brute force your embeddings

原始链接: https://softwaredoug.com/blog/2026/07/29/just-brute-force-embeddings

许多工程师会下意识地采用复杂的向量数据库,却未考虑其规模是否真的需要如此高的开销。正如“简单的暴力算法往往优于复杂算法”这一观点,作者证明对于约 100 万条文档的数据集,向量数据库通常是不必要的。 仅需使用 NumPy 的一行 Python 代码——计算查询向量与文档嵌入矩阵之间的点积——其速度快得惊人。在标准的 M4 MacBook Pro 上,该方法处理 100 万条文档的延迟不到 100 毫秒,这证明了“穷举搜索”对于许多实际应用场景而言通常已经足够。 团队不应投入昂贵且复杂的架构,或花费数月时间进行部署,而应首先评估简单的内存解决方案(如 NumPy 或 FAISS)是否能满足性能需求。对于大多数中低流量的应用,最简单的方法不仅更易于维护,而且通常比专用向量数据库更快、更高效。

关于“暴力破解嵌入(brute force your embeddings)”的 Hacker News 讨论核心在于:对于许多搜索任务而言,复杂的向量数据库往往是不必要的。开发者完全可以通过简单的“暴力”比对来获得高性能,例如在二进制嵌入上计算汉明距离,或使用基础的线性扫描。 参与者认为,现代硬件在利用 SIMD 优化或二进制量化技术时,可以在几分之一秒内处理数百万次比对。普遍共识是,对于许多使用场景,维护简单的内存结构或使用 SQLite 等轻量级工具,比部署专门的向量数据库基础设施更高效且更易于维护。用户建议只有在基础的暴力搜索方法无法满足性能需求时,才考虑复杂的解决方案。正如一位评论者所指出的,这种方法符合“COST”(优于单线程的配置)理念,即主张采用简单且可扩展的方案,而非过早引入复杂性。
相关文章

原文

When I wrote embedded C code in the 2000s we latched onto something Raymond Chen, wrote in passing

My O(n) algorithm can run circles around your O(log n) algorithm; why much of what you learned in school simply doesn’t matter

True of a sorting algorithm. True of vector search.

People think they need a vector database. But often they have like 1m docs to search. Numpy can brute-force an array of float32s very fast:

Index Size Client Threads QPS Avg Latency
1000000 1 79.7 0.012s
1000000 10 170.5 0.058s
8841823 1 9.34 0.106s
8841823 10 18.34 0.106s

This is literally just this line of Python code, on 384 dim embeddings, running on my M4 MBP.

# Dot product against all
scores = self.doc_vectors @ query_vector.astype(np.float32, copy=False)

I work with a lot of teams that don’t need the complexity of a vector database. They have ~1m documents to search. They have low query traffic, and write their embeddings all up front. They don’t need to buy a multi-million dollar vector database, or spend 6 months learning to operate it.

For low enough n, just brute force the embeddings until you can’t bear to. As fellow search traveler Jo Kristian Bergum says “an exhaustive search may be all you need”.

A little past that, maybe think about a database? Or heck, just load them all in memory in FAISS or something and call it done.


As a footnote, this is just naive numpy operations, it could probably be faster. As Andreas Erickson says, throughput can be improved here by giving threads more than one query during the scan). And we could be doing a lot more during the search to collect into a top-n heap than what numpy does.

Join me for Vectors Week, a series of events about vector retrieval, hybrid search, and building your own vector database.

联系我们 contact @ memedata.com