FROM mobilephone724
PGVECTOR AND VECTOR DATABASE
序言 pgvector是一个向量搜索(根据近似度)的插件,用来加速AKNN(approximate nearest neighbor)。 PASE中提到,向量ANN算法包括4类 tree-based algorithms KD-Tree RTree quantization-based algorithms IVFFlat IVFADC IMI graph based algorithms HNSW NSG SSG hash-base algorithms LSH pgvector 包括两个算法,IVFFlat 和 HNSW,后续内容将以这两个算法的内容及其实现展开。 IVFFlat 概览 IVFFlat 算法主要包括以下几个步骤 索引构建阶段 使用 KMeans 将数据集划分成多个簇(cluster) 查询阶段 通过每个簇的中心点(向量是高维的点)获取N个最近的簇 遍历这N个簇的所有点,从中找到最近的K个点 算法介绍 基础算法kmeans reference k-means clustering - Wikipedia 算法目标:选取K个中心点,使得数据集中的所有点到其最近的中心点“距离”之和最近,以平方和距离为例: Given a set of observations $(x_1, x_2, \dots, x_n)$, where each observation is a $d$-dimensional real vector, k-means clustering aims to partition the $n$ observations into $k$ ($\leq n$) sets $S = {S_1, S_2, \dot, S_k}$ so as to minimize the within-cluster sum of squares (WCSS). Formally, the objective is to find: 算法过程: 我们可以很容易的证明目标函数是关于$S$的凸函数 Given an initial set of $k$ means $m_1^{1}, \dots , m_k^{(1)}$ (see below), the algorithm proceeds by alternating between two steps: ...