跳到内容

ANN

近似最近邻 (ANN) 索引配置,用于存储向量嵌入。

后端

backend: faiss|hnsw|annoy|numpy|torch|pgvector|sqlite|custom

设置 ANN 后端。默认为 faiss。其他后端可通过 ann 扩展包获得。通过将此参数设置为完全可解析的类字符串来设置自定义后端。

后端特定设置通过一个与后端同名(例如 annoy, faiss 或 hnsw)的相应配置对象进行设置。这些是可选的,如果省略则设置为默认值。

faiss

faiss:
    components: comma separated list of components - defaults to "IDMap,Flat" for small
                indices and "IVFx,Flat" for larger indexes where
                x = min(4 * sqrt(embeddings count), embeddings count / 39)
                automatically calculates number of IVF cells when omitted (supports "IVF,Flat")
    nprobe: search probe setting (int) - defaults to x/16 (as defined above)
            for larger indexes
    nflip: same as nprobe - only used with binary hash indexes
    quantize: store vectors with x-bit precision vs 32-bit (boolean|int)
              true sets 8-bit precision, false disables, int sets specified
              precision
    mmap: load as on-disk index (boolean) - trade query response time for a
          smaller RAM footprint, defaults to false
    sample: percent of data to use for model training (0.0 - 1.0)
            reduces indexing time for larger (>1M+ row) indexes, defaults to 1.0

Faiss 支持浮点索引和二进制索引。浮点索引是默认设置。二进制索引用于索引标量量化数据集。

有关更多信息,请参阅以下 Faiss 文档链接。

注意:对于 macOS 用户,上游软件包中的一个现有错误将处理线程数限制为 1。此限制在内部进行管理,以防止系统崩溃。

hnsw

hnsw:
    efconstruction:  ef_construction param for init_index (int) - defaults to 200
    m: M param for init_index (int) - defaults to 16
    randomseed: random-seed param for init_index (int) - defaults to 100
    efsearch: ef search param (int) - defaults to None and not set

有关这些参数的更多信息,请参阅 Hnswlib 文档

annoy

annoy:
    ntrees: number of trees (int) - defaults to 10
    searchk: search_k search setting (int) - defaults to -1

有关这些参数的更多信息,请参阅 Annoy 文档。请注意,annoy 索引创建后无法修改,不支持 upserts/deletes 及其他修改。

numpy

NumPy 后端是 k-最近邻 后端。它设计简洁,适用于较小的数据集。

torch 后端支持相同的选项。唯一的区别在于向量可以使用 GPU 进行搜索。

pgvector

pgvector:
    url: database url connection string, alternatively can be set via
         ANN_URL environment variable
    schema: database schema to store vectors - defaults to being
            determined by the database
    table: database table to store vectors - defaults to `vectors`
    precision: vector float precision (half or full) - defaults to `full`
    efconstruction:  ef_construction param (int) - defaults to 200
    m: M param for init_index (int) - defaults to 16

pgvector 后端将嵌入存储在 Postgres 数据库中。有关这些参数的更多信息,请参阅 pgvector 文档。有关如何构建 URL 连接字符串的更多信息,请参阅 SQLAlchemy 文档。

sqlite

sqlite:
    quantize: store vectors with x-bit precision vs 32-bit (boolean|int)
              true sets 8-bit precision, false disables, int sets specified
              precision
    table: database table to store vectors - defaults to `vectors`

SQLite 后端使用 sqlite-vec 将嵌入存储在 SQLite 数据库中。此后端支持存储级别的 1 位和 8 位量化。

有关如何在 MacOS 上运行此 ANN 的信息,请参阅 此说明