结构体 faiss::gpu::GpuIndexCagra
-
结构体 GpuIndexCagra 继承自 faiss::gpu::GpuIndex
公共类型
-
类型别名 component_t = float
-
类型别名 distance_t = float
公共函数
-
GpuIndexCagra(GpuResourcesProvider *provider, int dims, faiss::MetricType metric = faiss::METRIC_L2, GpuIndexCagraConfig config = GpuIndexCagraConfig())
-
virtual void train(idx_t n, const float *x) override
基于给定的向量数据训练 CAGRA。
-
void copyFrom(const faiss::IndexHNSWCagra *index)
从给定的 CPU 索引初始化自身;将覆盖自身中的所有数据
-
void copyTo(faiss::IndexHNSWCagra *index) const
将自身复制到给定的 CPU 索引;将覆盖索引实例中的所有数据
-
virtual void reset() override
从数据库中删除所有元素。
-
int getDevice() const
返回此索引所在的设备。
-
std::shared_ptr<GpuResources> getResources()
返回对我们的 GpuResources 对象的引用,该对象管理 GPU 上的内存、流和句柄资源
-
void setMinPagingSize(size_t size)
设置我们使用 CPU -> GPU 分页搜索的最小数据大小(以 MiB 为单位)
-
size_t getMinPagingSize() const
返回分页搜索的当前最小数据大小。
-
virtual void add(idx_t, const float *x) override
x
可以驻留在 CPU 或任何 GPU 上;根据需要执行复制。如果添加集太大,则处理分页添加;调用 addInternal_
-
virtual void add_with_ids(idx_t n, const float *x, const idx_t *ids) override
x
和ids
可以驻留在 CPU 或任何 GPU 上;根据需要执行复制。如果添加集太大,则处理分页添加;调用 addInternal_
-
virtual void assign(idx_t n, const float *x, idx_t *labels, idx_t k = 1) const override
x
和labels
可以驻留在 CPU 或任何 GPU 上;根据需要执行复制
-
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, const SearchParameters *params = nullptr) const override
x
、distances
和labels
可以驻留在 CPU 或任何 GPU 上;根据需要执行复制
-
virtual void search_and_reconstruct(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, float *recons, const SearchParameters *params = nullptr) const override
x
、distances
、labels
和recons
可以驻留在 CPU 或任何 GPU 上;根据需要执行复制
-
virtual void compute_residual(const float *x, float *residual, idx_t key) const override
重写以强制 GPU 索引提供其自己的 GPU 友好实现
-
virtual void compute_residual_n(idx_t n, const float *xs, float *residuals, const idx_t *keys) const override
重写以强制 GPU 索引提供其自己的 GPU 友好实现
-
virtual void range_search(idx_t n, const float *x, float radius, RangeSearchResult *result, const SearchParameters *params = nullptr) const
查询维度为 d 的 n 个向量到索引。
返回所有距离 < radius 的向量。请注意,许多索引不实现 range_search(只有 k-NN 搜索是强制性的)。
- 参数:
n – 向量数
x – 要搜索的输入向量,大小为 n * d
radius – 搜索半径
result – 结果表
-
virtual size_t remove_ids(const IDSelector &sel)
从索引中删除ID。并非所有索引都支持。返回删除的元素数量。
-
virtual void reconstruct(idx_t key, float *recons) const
重建存储的向量(如果是有损编码,则是近似值)
对于某些索引,此函数可能未定义
- 参数:
key – 要重建的向量的ID
recons – 重建的向量(大小为d)
-
virtual void reconstruct_batch(idx_t n, const idx_t *keys, float *recons) const
重建多个存储的向量(如果是损失编码,则是近似值)
对于某些索引,此函数可能未定义
- 参数:
n – 要重建的向量数
keys – 要重建的向量的ID(大小为n)
recons – 重建的向量(大小为n * d)
-
virtual void reconstruct_n(idx_t i0, idx_t ni, float *recons) const
重建向量i0到i0 + ni - 1
对于某些索引,此函数可能未定义
- 参数:
i0 – 序列中第一个向量的索引
ni – 序列中向量的数量
recons – 重建的向量(大小为ni * d)
-
virtual DistanceComputer *get_distance_computer() const
获取此索引类型的 DistanceComputer (在 AuxIndexStructures 中定义) 对象。
DistanceComputer 针对支持对其向量进行随机访问的索引实现。
-
virtual size_t sa_code_size() const
生成的代码的大小(以字节为单位)
-
virtual void sa_encode(idx_t n, const float *x, uint8_t *bytes) const
编码一组向量
- 参数:
n – 向量数
x – 输入向量,大小为 n * d
bytes – 输出编码向量,大小为 n * sa_code_size()
-
virtual void sa_decode(idx_t n, const uint8_t *bytes, float *x) const
解码一组向量
- 参数:
n – 向量数
bytes – 输入编码向量,大小为 n * sa_code_size()
x – 输出向量,大小为 n * d
-
virtual void merge_from(Index &otherIndex, idx_t add_id = 0)
将条目从另一个数据集移动到自身。输出时,other 为空。add_id 被添加到所有移动的ID (对于顺序ID,这将是 this->ntotal)
-
virtual void check_compatible_for_merge(const Index &otherIndex) const
检查两个索引是否兼容(即,它们以相同的方式训练并且具有相同的参数)。否则抛出异常。
-
virtual void add_sa_codes(idx_t n, const uint8_t *codes, const idx_t *xids)
添加使用独立编解码器计算的向量
- 参数:
codes – 要添加的代码,大小为 n * sa_code_size()
xids – 相应的ID,大小为 n
公共成员
-
int d
向量维度
-
idx_t ntotal
索引向量的总数
-
bool verbose
详细级别
-
bool is_trained
如果 Index 不需要训练,或者已经完成训练,则设置
-
MetricType metric_type
此索引用于搜索的度量类型
-
float metric_arg
度量类型的参数
保护函数
-
virtual bool addImplRequiresIDs_() const override
addImpl_ 是否需要 IDs? 如果是,且未提供 IDs,我们将根据添加 IDs 的顺序依次生成它们
-
virtual void addImpl_(idx_t n, const float *x, const idx_t *ids) override
覆盖以实际执行添加 所有数据都保证驻留在我们的设备上
-
virtual void searchImpl_(idx_t n, const float *x, int k, float *distances, idx_t *labels, const SearchParameters *search_params) const override
从 GpuIndex 调用以进行搜索。
保护属性
-
const GpuIndexCagraConfig cagraConfig_
我们的配置选项。
-
std::shared_ptr<CuvsCagra> index_
我们拥有的实例; 包含倒排列表。
-
std::shared_ptr<GpuResources> resources_
管理设备的流、cuBLAS 句柄和暂存内存。
-
const GpuIndexConfig config_
我们的配置选项。
-
size_t minPagedSize_
我们从 CPU 到 GPU 分页复制的大小上限。
-
类型别名 component_t = float