为什么以及什么
向量数据库现在是非常热门的话题。我一直对它们是什么以及它们是如何在背后工作的感到好奇,所以我们自己来构建一个。从头开始构建一个全新的数据库并不现实,我们需要一些构建块,或者,直接使用一个真正的数据库系统。Postgres 因其扩展性而享有长期的声誉,这使它成为我们需求的完美选择,像 pgvector 这样的项目已经证明,将向量支持作为扩展添加到 Postgres 是可行的。
我们将为 Postgres 实现向量支持,但需要实现哪些详细功能呢?这个问题并不难,维基百科对 向量数据库 的定义为我们指明了正确的方向:
A vector database, vector store or vector search engine is a database that can store vectors (fixed-length lists of numbers) along with other data items. Vector databases typically implement one or more Approximate Nearest Neighbor algorithms so that one can search the database with a query vector to retrieve the closest matching database records
好的,那么我们需要使 Postgres 能够存储向量,并能够执行 Top-K 查询。即对于给定的输入向量,Postgres 应返回与之最相似(或最近)的 K 个向量。如果用 SQL 来表示,它可能看起来像这样:
-- 创建一个表,其中有一个 `vector(3)` 类型的列,3 是向量的维度
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
-- 插入向量,Postgres 应该能够存储它们!
INSERT INTO items (embedding

最低0.47元/天 解锁文章
983

被折叠的 条评论
为什么被折叠?



