Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nautaa committed Oct 17, 2024
1 parent 7cbb0fa commit b667a69
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
9 changes: 6 additions & 3 deletions docs/docs/game/miniob-vectordb.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ SELECT * FROM TAB_VEC ORDER BY L2_DISTANCE(B, '[1,2,3]') LIMIT 1;
### 题目六:ann-benchmarks

[ann-benchmarks](https://github.com/erikbern/ann-benchmarks) 是一个用于评估近似最近邻(Approximate Nearest Neighbor, ANN)搜索算法性能的工具和框架。我们使用 ann-benchmarks 来测试 MiniOB 向量搜索相关功能。
本地运行 ann-benchmarks 测试的步骤如下:
本地运行支持 MiniOB 的 ann-benchmarks 测试的步骤如下:

赛题测试程序中运行的 ann-benchmarks 只针对 `fashion-mnist-784-euclidean` 数据集进行测试,`--runs` 参数为1,测试使用的 python 脚本与 [ann-benchmarks](https://github.com/nautaa/ann-benchmarks/tree/miniob_ann) 完全相同,指定向量索引参数 `probes = 5, lists = 245`
测试程序不对性能做过多的限制,满足如下要求即为通过:
Expand All @@ -147,7 +147,7 @@ SELECT * FROM TAB_VEC ORDER BY L2_DISTANCE(B, '[1,2,3]') LIMIT 1;

#### 在 MiniOB 上运行 ann-benchmark

1. 下载 ann-benchmarks 代码
1. 下载 ann-benchmarks 代码
```
git clone https://github.com/nautaa/ann-benchmarks.git -b miniob_ann
```
Expand Down Expand Up @@ -201,6 +201,9 @@ SELECT * FROM TAB_VEC ORDER BY L2_DISTANCE(B, '[1,2,3]') LIMIT 1;

## 参考资料
[向量数据库](https://en.wikipedia.org/wiki/Vector_database)

[pgvector](https://github.com/pgvector/pgvector)

[ivfflat 原理介绍](https://www.timescale.com/blog/nearest-neighbor-indexes-what-are-ivfflat-indexes-in-pgvector-and-how-do-they-work/)
[ann-benchmarks](https://github.com/nautaa/ann-benchmarks.git)

[支持 MiniOB 的 ann-benchmarks fork 仓库](https://github.com/nautaa/ann-benchmarks/tree/miniob_ann)
10 changes: 5 additions & 5 deletions src/observer/common/type/vector_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class VectorType : public DataType
VectorType() : DataType(AttrType::VECTORS) {}
virtual ~VectorType() {}

int compare(const Value &left, const Value &right) const override {return INT32_MAX; }
int compare(const Value &left, const Value &right) const override { return INT32_MAX; }

RC add(const Value &left, const Value &right, Value &result) const override {return RC::UNIMPLEMENTED; }
RC subtract(const Value &left, const Value &right, Value &result) const override {return RC::UNIMPLEMENTED; }
RC multiply(const Value &left, const Value &right, Value &result) const override {return RC::UNIMPLEMENTED; }
RC add(const Value &left, const Value &right, Value &result) const override { return RC::UNIMPLEMENTED; }
RC subtract(const Value &left, const Value &right, Value &result) const override { return RC::UNIMPLEMENTED; }
RC multiply(const Value &left, const Value &right, Value &result) const override { return RC::UNIMPLEMENTED; }

RC to_string(const Value &val, string &result) const override {return RC::UNIMPLEMENTED; }
RC to_string(const Value &val, string &result) const override { return RC::UNIMPLEMENTED; }
};
14 changes: 10 additions & 4 deletions src/observer/storage/index/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ class Index
Index() = default;
virtual ~Index() = default;

virtual RC create(Table *table, const char *file_name, const IndexMeta &index_meta, const FieldMeta &field_meta) {return RC::UNSUPPORTED; }
virtual RC open(Table *table, const char *file_name, const IndexMeta &index_meta, const FieldMeta &field_meta) {return RC::UNSUPPORTED; }

virtual bool is_vector_index() {return false; }
virtual RC create(Table *table, const char *file_name, const IndexMeta &index_meta, const FieldMeta &field_meta)
{
return RC::UNSUPPORTED;
}
virtual RC open(Table *table, const char *file_name, const IndexMeta &index_meta, const FieldMeta &field_meta)
{
return RC::UNSUPPORTED;
}

virtual bool is_vector_index() { return false; }

const IndexMeta &index_meta() const { return index_meta_; }

Expand Down
14 changes: 7 additions & 7 deletions src/observer/storage/index/ivfflat_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ See the Mulan PSL v2 for more details. */
class IvfflatIndex : public Index
{
public:
IvfflatIndex() {};
IvfflatIndex(){};
virtual ~IvfflatIndex() noexcept {};

RC create(Table *table, const char *file_name, const IndexMeta &index_meta, const FieldMeta &field_meta)
Expand All @@ -28,11 +28,11 @@ class IvfflatIndex : public Index
};
RC open(Table *table, const char *file_name, const IndexMeta &index_meta, const FieldMeta &field_meta)
{

return RC::UNIMPLEMENTED;
};

vector<RID> ann_search(const vector<float> &base_vector, size_t limit) {return vector<RID>(); }
vector<RID> ann_search(const vector<float> &base_vector, size_t limit) { return vector<RID>(); }

RC close() { return RC::UNIMPLEMENTED; }

Expand All @@ -42,8 +42,8 @@ class IvfflatIndex : public Index
RC sync() override { return RC::UNIMPLEMENTED; };

private:
bool inited_ = false;
Table * table_ = nullptr;
int lists_ = 1;
int probes_ = 1;
bool inited_ = false;
Table *table_ = nullptr;
int lists_ = 1;
int probes_ = 1;
};

0 comments on commit b667a69

Please sign in to comment.