matrixone icon indicating copy to clipboard operation
matrixone copied to clipboard

[Feature Request]: Vector type index

Open fengttt opened this issue 3 years ago • 14 comments

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

fengttt avatar Jul 13 '23 03:07 fengttt

@arjunsk @XuPeng-SH knows a lot of things about how to index the vector type. Please include him for design/doc review

fengttt avatar Jul 19 '23 17:07 fengttt

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.

flying-x avatar Jul 19 '23 17:07 flying-x

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.

arjunsk avatar Jan 08 '24 03:01 arjunsk

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

arjunsk avatar Jan 10 '24 05:01 arjunsk

Progress:

  1. With the workaround, I was able to index a table with
  • 1million rows of vecf32(148)
  • 1million rows of vecf32(1024)
  1. Doing some more analysis on cluster skews in datasets (random dataset vs GPT dataset)

arjunsk avatar Jan 19 '24 19:01 arjunsk

Update

  1. 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
  1. The insert performance issue has just now been unblocked. Will continue with the testing.
  2. Implementation-wise, vector index data storage is done. Using it in optimizer will be done by @aunjgr
  3. During the initial round of benchmarking, a few improvement points have been discovered. Will implement the same in a new PR.

arjunsk avatar Jan 25 '24 08:01 arjunsk

  • 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

arjunsk avatar Jan 27 '24 01:01 arjunsk

The PR is merged. It is ready for testing.

arjunsk avatar Jan 29 '24 20:01 arjunsk

Updated the document with latest changes to KNN query.

https://doc.weixin.qq.com/doc/w3_AawAhAZmAIkZ9vRK0hiQVykQx3tTi?scode=AJsA6gc3AA86DSyJdmAawAhAZmAIk

CC: @yangj1211

arjunsk avatar Mar 18 '24 18:03 arjunsk

test done,performance issue:#15191

ghost avatar Apr 09 '24 09:04 ghost

Minor document update: https://doc.weixin.qq.com/doc/w3_AawAhAZmAIkZ9vRK0hiQVykQx3tTi?scode=AJsA6gc3AA86DSyJdmAawAhAZmAIk

Added

image

New Vector Functions:

  • L2_distance
  • Normalize_L2

https://doc.weixin.qq.com/doc/w3_AawAhAZmAIkoCN5aJHPQjqV3v8hKw?scode=AJsA6gc3AA8RKAaMz6AawAhAZmAIk

arjunsk avatar Apr 18 '24 01:04 arjunsk

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

ghost avatar May 09 '24 07:05 ghost

1.2 vector index benchmark 只测试了128dim和960dim 100万数据的性能,时间原因其他dim的性能可以再下一版本再测试

ghost avatar May 09 '24 11:05 ghost

done

aressu1985 avatar Jul 02 '24 10:07 aressu1985