[Feature Request]: Vector type index
Is there an existing issue for the same feature request?
- [X] I have checked the existing issues.
Is your feature request related to a problem?
create index, and use index to accelerate query.
Describe the feature you'd like
This one is much more trickier, compared to type and function. Need design doc.
Describe implementation you've considered
No response
Documentation, Adoption, Use Case, Migration Strategy
No response
Additional information
No response
@arjunsk @XuPeng-SH knows a lot of things about how to index the vector type. Please include him for design/doc review
I don't know much about vector indexing but a use case is to do set operations with similarity in mind.
set1 = select * from vectors where query=q1 set2 = select * from vectors where query=q2
intersection = select p, q from set1, set2 where p == q
obviously, p == q can't be exactly equal, it needs to be some kind of vector equal function.
Currently getting OOM for a table with 1 million rows of VECF32[1024]. We need to optimize the window strategy.
Current Mapping SQL looks like below:
SELECT `__mo_index_entries_tbl`.`__mo_index_centroid_version_fk`,
`__mo_index_entries_tbl`.`__mo_index_centroid_id_fk`,
`__mo_index_entries_tbl`.`__mo_index_table_pk` FROM
(
SELECT
centroids.`__mo_index_centroid_version` as __mo_index_centroid_version_fk,
centroids.`__mo_index_centroid_id` as __mo_index_centroid_id_fk,
tbl.id as __mo_index_table_pk,
ROW_NUMBER() OVER (PARTITION BY tbl.id ORDER BY l2_distance(centroids.__mo_index_centroid, normalize_l2(tbl.embedding) ) ) as `__mo_index_rn`
FROM tbl
CROSS JOIN
(select * from `__mo_index_secondary_ff6b099e-9b2f-11ee-9b85-723e89f7b974` where `__mo_index_centroid_version` = (select CAST(`__mo_index_val` as BIGINT) from `__mo_index_secondary_ff6b0890-9b2f-11ee-9b85-723e89f7b974` where `__mo_index_key` = 'version')) as centroids
)`__mo_index_entries_tbl` WHERE `__mo_index_entries_tbl`.`__mo_index_rn` = 1;
Also getting another error
SQL Error [20101] [HY000]: internal error: message body 262014371 is too large, max is 104857600
@nnsgmsone suggested to reduce the window size.
Blocked by 2 OOM issues
https://github.com/matrixorigin/MO-Cloud/issues/2276
https://github.com/matrixorigin/MO-Cloud/issues/2277
Workaround
https://github.com/matrixorigin/matrixone/issues/14064
Progress:
- With the workaround, I was able to index a table with
- 1million rows of vecf32(148)
- 1million rows of vecf32(1024)
- Doing some more analysis on cluster skews in datasets (random dataset vs GPT dataset)
Update
- The correctness of the Vector Index has been validated. I need to redo some retesting before posting the official results. Unofficial details are here:
- https://github.com/matrixorigin/docs/pull/269
- https://github.com/matrixorigin/docs/pull/264
- The insert performance issue has just now been unblocked. Will continue with the testing.
- Implementation-wise, vector index data storage is done. Using it in optimizer will be done by @aunjgr
- During the initial round of benchmarking, a few improvement points have been discovered. Will implement the same in a new PR.
- The vector index is almost ready for testing. Waiting for this PR to be merged: https://github.com/matrixorigin/matrixone/pull/14402
- The document: Vector Index Document
- Formal Benchmarking is pending
CC: @yangj1211
The PR is merged. It is ready for testing.
Updated the document with latest changes to KNN query.
https://doc.weixin.qq.com/doc/w3_AawAhAZmAIkZ9vRK0hiQVykQx3tTi?scode=AJsA6gc3AA86DSyJdmAawAhAZmAIk
CC: @yangj1211
test done,performance issue:#15191
Minor document update: https://doc.weixin.qq.com/doc/w3_AawAhAZmAIkZ9vRK0hiQVykQx3tTi?scode=AJsA6gc3AA86DSyJdmAawAhAZmAIk
Added
New Vector Functions:
- L2_distance
- Normalize_L2
https://doc.weixin.qq.com/doc/w3_AawAhAZmAIkoCN5aJHPQjqV3v8hKw?scode=AJsA6gc3AA8RKAaMz6AawAhAZmAIk
after performance improvment test again done commit:ad5d8c6c43a021760896df846fcf35dff93cfd8f performance results:https://doc.weixin.qq.com/sheet/e3_AYYAgwazACsB4L72hnoQ1eAEU31N6?scode=AJsA6gc3AA8QPAY9JuAYYAgwazACs&tab=BB08J2 performance issue:https://github.com/matrixorigin/matrixone/issues/15191
1.2 vector index benchmark 只测试了128dim和960dim 100万数据的性能,时间原因其他dim的性能可以再下一版本再测试
done