-
Notifications
You must be signed in to change notification settings - Fork 554
feat: add fts support #408
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
Open
egolearner
wants to merge
24
commits into
alibaba:main
Choose a base branch
from
egolearner:feat/fts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
764532e
feat: add fts support
egolearner 288ea80
fix mac compile & ci
egolearner 0704718
refactor parse fts & add fts debug text
egolearner 784e5fd
fix some problems
egolearner 7ae49af
refactor(fts_column): reorganize into tokenizer/, posting/, iterator/…
egolearner 84dd52a
perf: or use multi_get
egolearner 22a612f
perf: optimize disjunction iterator
egolearner 3a05a15
perf: fts use hashskiplist
egolearner a7da75e
refactor batch_get_postings
egolearner 12a8d56
perf: optimize iterator virtual function
egolearner 34740d1
bench limit max_queries
egolearner ab52311
perf: use PinnableSlice
egolearner 14882eb
perf: bitpacked avx2
egolearner 3badf49
chore: rm unnecessary checkpoint
egolearner ca5808e
perf: cache block_max_info_for result to skip repeated binary searche…
egolearner bbb74ae
perf: precompute BM25 IDF weight per term to eliminate log() from sco…
egolearner 5ea99ff
perf: cache SIMD dispatch function pointers in iterator to eliminate …
egolearner d001175
rename
egolearner 713b200
perf: push filter down into FTS composite iterators
egolearner 3919414
refactor: drop block-max helpers superseded by block_max_info_for
egolearner 647e0ff
perf: candidate-driven (brute-force) FTS evaluation
egolearner 04cb8f6
PartialMerge no optimize
egolearner 2739620
fix fts score
egolearner 122fb51
python binding support fts
egolearner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Auto-generated files — collapsed in GitHub PR diffs | ||
| src/db/index/column/fts_column/gen/** linguist-generated=true | ||
| src/db/sqlengine/antlr/gen/** linguist-generated=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| # Copyright 2025-present the zvec project | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Tests for FTS (Full-Text Search) query support in the Python SDK.""" | ||
|
|
||
| import pickle | ||
|
|
||
| import pytest | ||
|
|
||
| from zvec.model.param.query import Fts, Query | ||
|
|
||
|
|
||
| class TestFtsQueryValidation: | ||
| """Test FTS parameter validation in Query dataclass.""" | ||
|
|
||
| def test_fts_query_string_only(self): | ||
| """Query with only query_string in Fts should be valid.""" | ||
| q = Query( | ||
| field_name="content", fts=Fts(query_string='+hello -world "exact phrase"') | ||
| ) | ||
| q._validate() | ||
| assert q.fts.query_string == '+hello -world "exact phrase"' | ||
| assert q.fts.match_string is None | ||
| assert q.has_fts() is True | ||
|
|
||
| def test_fts_match_string_only(self): | ||
| """Query with only match_string in Fts should be valid.""" | ||
| q = Query(field_name="content", fts=Fts(match_string="machine learning")) | ||
| q._validate() | ||
| assert q.fts.match_string == "machine learning" | ||
| assert q.fts.query_string is None | ||
| assert q.has_fts() is True | ||
|
|
||
| def test_fts_query_string_and_match_string_mutually_exclusive(self): | ||
| """Cannot provide both query_string and match_string in Fts.""" | ||
| q = Query( | ||
| field_name="content", | ||
| fts=Fts(query_string="+hello", match_string="hello world"), | ||
| ) | ||
| with pytest.raises(ValueError, match="mutually exclusive"): | ||
| q._validate() | ||
|
|
||
| def test_no_fts(self): | ||
| """Query without FTS fields should have has_fts() == False.""" | ||
| q = Query(field_name="embedding", vector=[0.1, 0.2, 0.3]) | ||
| assert q.has_fts() is False | ||
|
|
||
| def test_vector_and_fts_mutually_exclusive(self): | ||
| """Cannot combine vector search with FTS in a single Query.""" | ||
| q = Query( | ||
| field_name="embedding", | ||
| vector=[0.1, 0.2, 0.3], | ||
| fts=Fts(match_string="deep learning"), | ||
| ) | ||
| with pytest.raises(ValueError, match="Cannot combine fts with vector search"): | ||
| q._validate() | ||
|
|
||
| def test_fts_without_vector_or_id(self): | ||
| """Query with only FTS (no vector, no id) should be valid.""" | ||
| q = Query(field_name="content", fts=Fts(query_string="hello")) | ||
| q._validate() | ||
| assert q.has_vector() is False | ||
| assert q.has_id() is False | ||
| assert q.has_fts() is True | ||
|
|
||
|
|
||
| class TestFtsQueryBinding: | ||
| """Test FTS binding layer (_FtsQuery).""" | ||
|
|
||
| def test_import_fts_query(self): | ||
| """_FtsQuery should be importable from _zvec.param.""" | ||
| from _zvec.param import _FtsQuery | ||
|
|
||
| fts = _FtsQuery() | ||
| assert fts.query_string == "" | ||
| assert fts.match_string == "" | ||
|
|
||
| def test_fts_query_set_fields(self): | ||
| """Setting fields on _FtsQuery should work.""" | ||
| from _zvec.param import _FtsQuery | ||
|
|
||
| fts = _FtsQuery() | ||
| fts.query_string = "+hello -world" | ||
| assert fts.query_string == "+hello -world" | ||
|
|
||
| fts2 = _FtsQuery() | ||
| fts2.match_string = "machine learning" | ||
| assert fts2.match_string == "machine learning" | ||
|
|
||
| def test_fts_query_pickle(self): | ||
| """_FtsQuery should support pickling.""" | ||
| from _zvec.param import _FtsQuery | ||
|
|
||
| fts = _FtsQuery() | ||
| fts.query_string = "+vector search" | ||
| fts.match_string = "" | ||
|
|
||
| data = pickle.dumps(fts) | ||
| restored = pickle.loads(data) | ||
| assert restored.query_string == "+vector search" | ||
| assert restored.match_string == "" | ||
|
|
||
| def test_vector_query_fts_field(self): | ||
| """_VectorQuery should have fts_query field.""" | ||
| from _zvec.param import _FtsQuery, _VectorQuery | ||
|
|
||
| vq = _VectorQuery() | ||
| # fts_query should be None by default (optional) | ||
| assert vq.fts_query is None | ||
|
|
||
| # set fts_query | ||
| fts = _FtsQuery() | ||
| fts.query_string = "hello" | ||
| vq.fts_query = fts | ||
| assert vq.fts_query is not None | ||
| assert vq.fts_query.query_string == "hello" | ||
|
|
||
| def test_vector_query_pickle_with_fts(self): | ||
| """_VectorQuery with fts_query should survive pickling.""" | ||
| from _zvec.param import _FtsQuery, _VectorQuery | ||
|
|
||
| vq = _VectorQuery() | ||
| vq.topk = 10 | ||
| vq.field_name = "embedding" | ||
| fts = _FtsQuery() | ||
| fts.match_string = "test query" | ||
| vq.fts_query = fts | ||
|
|
||
| data = pickle.dumps(vq) | ||
| restored = pickle.loads(data) | ||
| assert restored.topk == 10 | ||
| assert restored.field_name == "embedding" | ||
| assert restored.fts_query is not None | ||
| assert restored.fts_query.match_string == "test query" | ||
|
|
||
| def test_vector_query_pickle_without_fts(self): | ||
| """_VectorQuery without fts_query should survive pickling.""" | ||
| from _zvec.param import _VectorQuery | ||
|
|
||
| vq = _VectorQuery() | ||
| vq.topk = 5 | ||
| vq.field_name = "vec" | ||
|
|
||
| data = pickle.dumps(vq) | ||
| restored = pickle.loads(data) | ||
| assert restored.topk == 5 | ||
| assert restored.field_name == "vec" | ||
| assert restored.fts_query is None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This naming "Fts" is a little bit too generic. Would it be more precise to name it after its underlying dependency, like _FtsQuery (binding) or FtsQueryParam (C++)?