https://simonwillison.net/atom/everything 11月12日 07:49
Redis 8 引入 HNSW 向量索引技术,实现高效扩展与读写并行
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Redis 8 在今年五月发布,其中一个重要更新是引入了 HNSW(Hierarchical Navigable Small World)向量索引技术。Salvatore Sanfilippo 在此基础上进行了大量优化,特别是在高效删除和更新索引方面。该技术能够将庞大的向量数据集分散到多个节点上,并实现读写操作的并行处理,从而有效解决了内存消耗大的问题。通过客户端合并来自多个实例的查询结果,可以轻松扩展至数亿向量。此外,通过哈希分片,写入操作也能被分散到不同实例,并行处理,大大提升了整体效率。

💡 HNSW 技术在 Redis 8 中的集成:Redis 8 引入了 HNSW(Hierarchical Navigable Small World)作为一种高效的向量索引技术,其实现细节和优化工作由 Salvatore Sanfilippo 完成。该技术源自 2016 年的学术论文,旨在提供一种高效的相似性搜索方法。

🚀 内存效率与扩展性:HNSW 索引技术通过在 Redis 中实现,能够有效处理内存消耗巨大的嵌入向量。文章重点介绍了如何将大型 HNSW 向量集分布到多个 Redis 节点上,从而实现数据集的水平扩展,应对海量向量数据的存储和检索需求。

⚡️ 并行读写能力:通过将向量数据集分散到多个实例,Redis 8 能够并行执行读写操作。查询时,客户端可以向所有相关实例发送查询请求,并在客户端合并结果,实现对海量数据的快速检索。写入时,通过哈希分片机制,可以将写入请求分散到不同的 Redis 实例,实现对慢速写入操作的并行处理,提升整体写入吞吐量。

🔗 源代码的透明性与可读性:文章强调了 Redis 在实现 HNSW 算法时,Salvatore Sanfilippo 编写的 C 语言代码具有极高的可读性和清晰的注释,这使得研究者和开发者能够更容易地理解和学习这一现代计算机科学领域中的重要技术。

Scaling HNSWs (via) Salvatore Sanfilippo spent much of this year working on vector sets for Redis , which first shipped in Redis 8 in May.

A big part of that work involved implementing HNSW - Hierarchical NavigableSmall World - an indexing technique first introduced in this 2016 paper by Yu. A. Malkov and D. A. Yashunin.

Salvatore's detailed notes on the Redis implementation here offer an immersive trip through a fascinating modern field of computer science. He describes several new contributions he's made to the HNSW algorithm, mainly around efficient deletion and updating of existing indexes.

Since embedding vectors are notoriously memory-hungry, I particularly appreciated this note about how you can scale a large HNSW vector set across many different nodes and run parallel queries against them for both reads and writes:

[...] if you have different vectors about the same use case split in different instances / keys, you can ask VSIM for the same query vector into all the instances, and add the WITHSCORES option (that returns the cosine distance) and merge the results client-side, and you have magically scaled your hundred of millions of vectors into multiple instances, splitting your dataset N times [One interesting thing about such a use case is that you can query the N instances in parallel using multiplexing, if your client library is smart enough].

Another very notable thing about HNSWs exposed in this raw way, is that you can finally scale writes very easily. Just hash your element modulo N, and target the resulting Redis key/instance. Multiple instances can absorb the (slow, but still fast for HNSW standards) writes at the same time, parallelizing an otherwise very slow process.

It's always exciting to see new implementations of fundamental algorithms and data structures like this make it into Redis because Salvatore's C code is so clearly commented and pleasant to read - here's vector-sets/hnsw.c and vector-sets/vset.c.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Redis HNSW 向量数据库 AI 机器学习 数据结构 算法 Scalability Vector Search Vector Indexing
相关文章