Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support vector subscript #329

Merged
merged 3 commits into from
Feb 2, 2024
Merged

feat: support vector subscript #329

merged 3 commits into from
Feb 2, 2024

Conversation

usamoi
Copy link
Collaborator

@usamoi usamoi commented Feb 1, 2024

Address #327

Now we support such a syntax:

CREATE TABLE t(val vector(3));
INSERT INTO t (val) SELECT ARRAY[random(), random(), random()]::real[] FROM generate_series(1, 100000);
CREATE INDEX t_vector_index on t using vectors((val[:1]::vector(1)) vector_l2_ops);
SELECT * FROM t ORDER BY val[:1]::vector(1) <-> '[0]' limit 10;

It's only supported by pg14, pg15 and pg16.

@VoVAllen
Copy link
Member

VoVAllen commented Feb 1, 2024

The syntax using real[] is not consistent with other usage with vectors. Is it necessary?
Is vectors a new function?

@usamoi
Copy link
Collaborator Author

usamoi commented Feb 1, 2024

The syntax using real[] is not consistent with other usage with vectors.

It's nothing about real[]. We store vectors in a column. This PR supports subscripts of value of vector type.

Is vectors a new function?

It's vectors AM handler. We create indexes on column val before and we create indexes on expression val[:1]::vector(1) now. You can get reference of syntax in https://www.postgresql.org/docs/current/sql-createindex.html.

@VoVAllen
Copy link
Member

VoVAllen commented Feb 1, 2024

Can I do CREATE INDEX t_vector_index on t using vectors((val[16:32]::vector(16)) vector_l2_ops); ?

@usamoi
Copy link
Collaborator Author

usamoi commented Feb 1, 2024

Can I do CREATE INDEX t_vector_index on t using vectors((val[16:32]::vector(16)) vector_l2_ops); ?

Yes.

@usamoi usamoi marked this pull request as ready for review February 2, 2024 05:29
VoVAllen
VoVAllen previously approved these changes Feb 2, 2024
Signed-off-by: usamoi <usamoi@outlook.com>
Signed-off-by: usamoi <usamoi@outlook.com>
Signed-off-by: usamoi <usamoi@outlook.com>
@usamoi usamoi added this pull request to the merge queue Feb 2, 2024
Merged via the queue into tensorchord:main with commit 7ec3c88 Feb 2, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants