Skip to content

vector-store: interval-based Tantivy commits#521

Merged
ewienik merged 4 commits into
scylladb:masterfrom
knowack1:vector-636-large-set-test-case
Jul 23, 2026
Merged

vector-store: interval-based Tantivy commits#521
ewienik merged 4 commits into
scylladb:masterfrom
knowack1:vector-636-large-set-test-case

Conversation

@knowack1

@knowack1 knowack1 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

This PR improves FTS indexing performance by replacing per-document Tantivy commits with an interval-based commit strategy. Commits are now triggered by a time interval (3 seconds). This reduces indexing time for 10,000 small documents from roughly 2 minutes to under 1 second.
Additionally, to prevent unlimited uncommitted documents, we force a commit when the number of pending documents exceeds the 10k threshold.

This change also fixes double reader reload. In default tantivy reader configuration (that we have) reload happens automatically after commit. My must take control over reload to drop InProgress correctly after reload.

A new validator test covers correctness at scale: it inserts 10,000 documents, waits for the index to catch up, then asserts that a rare-term BM25 search returns only the expected needle documents and that a common-term search respects the query LIMIT.
Indexing and query durations are measured and logged.

Fixes: VECTOR-636
Reference: VECTOR-621

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces deferred/periodic commit behavior for the Tantivy-backed full-text index to avoid committing on every document update, and adds an end-to-end validator test that exercises BM25 over a large document set.

Changes:

  • Add pending-commit tracking to the Tantivy FTS actor, committing on an interval and/or after enough pending bytes accumulate.
  • Update Tantivy unit tests to poll for visibility (since commits are deferred) and make the commit interval configurable in tests.
  • Optimize validator FTS document insertion by preparing the CQL statement once, and add a fts_large_document_set e2e test (10k docs) with basic timing instrumentation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/vector-store/src/fts_index/tantivy.rs Adds deferred commit machinery (pending bytes/dirty flag + interval tick) and updates unit tests accordingly.
crates/validator/src/fts.rs Reuses a prepared insert statement, adds duration logging helper, and introduces a large dataset FTS e2e test.
Comments suppressed due to low confidence (1)

crates/vector-store/src/fts_index/tantivy.rs:693

  • This test can become a false positive with the new deferred-commit behavior: counting immediately after add_doc can return 0 simply because the index hasn't committed yet. Waiting at least one commit interval before asserting makes it validate that the document truly was not indexed when memory allocation is denied.
        add_doc(&sender, 1, "should not be indexed").await;

        let key = make_index_key();
        let count = sender.count(key).await.unwrap();
        assert_eq!(count, 0);

Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
@knowack1 knowack1 changed the title Vector 636 large set test case Add interval-based Tantivy commits and large FTS dataset validator test Jul 15, 2026
@knowack1 knowack1 changed the title Add interval-based Tantivy commits and large FTS dataset validator test vector-store: interval-based Tantivy commits Jul 15, 2026
@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch from 1baad0a to c9038d6 Compare July 15, 2026 13:40
@knowack1
knowack1 requested a review from Copilot July 15, 2026 13:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
Comment thread crates/vector-store/src/fts_index/tantivy.rs
Comment thread crates/vector-store/src/fts_index/tantivy.rs
@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch from c9038d6 to d06911d Compare July 15, 2026 14:07
@knowack1
knowack1 requested a review from Copilot July 15, 2026 14:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
@knowack1
knowack1 marked this pull request as ready for review July 15, 2026 14:29

@m-szymon m-szymon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested that it decreases index build time dramatically.
Some concerns below to be clarified.

Comment thread crates/validator/src/fts.rs Outdated
Comment thread crates/validator/src/fts.rs
Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
Comment thread crates/vector-store/src/fts_index/tantivy.rs
@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch from d06911d to 4cf0366 Compare July 16, 2026 15:21
@knowack1
knowack1 requested a review from Copilot July 16, 2026 15:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

crates/vector-store/src/fts_index/tantivy.rs:426

  • tokio::select! cannot have an arm starting with an enum variant pattern (FtsIndex::Stats { .. } => { .. }). This will not compile, and it also suggests FtsIndex::Stats is not handled in the match msg block, making that match non-exhaustive.
                FtsIndex::Stats { index_key, tx } => {
                    let Some(state) = get_state(&states, table.as_ref(), &index_key) else {
                        _ = tx.send(Ok(FtsStats::default()));
                        continue;
                    };

Comment thread crates/vector-store/src/fts_index/tantivy.rs
Comment thread crates/vector-store/src/fts_index/tantivy.rs
Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch 2 times, most recently from 2bf1a5b to 05a79de Compare July 16, 2026 15:49
@knowack1
knowack1 requested a review from Copilot July 16, 2026 15:49
@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch from 05a79de to 72dd540 Compare July 16, 2026 15:52
Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
Comment thread crates/vector-store/src/fts_index/tantivy.rs
@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch 3 times, most recently from 093156c to c78703a Compare July 22, 2026 11:05
m-szymon
m-szymon previously approved these changes Jul 22, 2026
Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch 2 times, most recently from 48e2e43 to 25a8a98 Compare July 23, 2026 07:38
@ewienik
ewienik added this pull request to the merge queue Jul 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@knowack1

knowack1 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

AI says that the merge queue failure was caused by the infra, base on this output (ANNOTATIONS section)

$ gh run view --job=89163928461 --repo scylladb/vector-store

X gh-readonly-queue/master/pr-521-40131ad2468b53707781a957f66987f49678d9ee Rust · 29994219414
Triggered via merge_group about 1 hour ago

X cargo-test in 45m0s (ID 89163928461)
  ✓ Set up job
  ✓ Run actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
  ✓ Setup rust toolchain
  ✓ Print rustc version
  * Run cargo-test checks
  * Post Setup rust toolchain
  * Post Run actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10

ANNOTATIONS
X The hosted runner lost communication with the server. Anything in your workflow that terminates the runner process, starves it for CPU/Memory, or blocks its network access can cause this error.
cargo-test: .github#1


To see the logs for the failed steps, try: gh run view --log-failed --job=89163928461
View this run on GitHub: https://github.com/scylladb/vector-store/actions/runs/29994219414

But I am still looking at this.

@knowack1

Copy link
Copy Markdown
Collaborator Author

AI says that the merge queue failure was caused by the infra, base on this output (ANNOTATIONS section)

$ gh run view --job=89163928461 --repo scylladb/vector-store

X gh-readonly-queue/master/pr-521-40131ad2468b53707781a957f66987f49678d9ee Rust · 29994219414
Triggered via merge_group about 1 hour ago

X cargo-test in 45m0s (ID 89163928461)
  ✓ Set up job
  ✓ Run actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
  ✓ Setup rust toolchain
  ✓ Print rustc version
  * Run cargo-test checks
  * Post Setup rust toolchain
  * Post Run actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10

ANNOTATIONS
X The hosted runner lost communication with the server. Anything in your workflow that terminates the runner process, starves it for CPU/Memory, or blocks its network access can cause this error.
cargo-test: .github#1


To see the logs for the failed steps, try: gh run view --log-failed --job=89163928461
View this run on GitHub: https://github.com/scylladb/vector-store/actions/runs/29994219414

But I am still looking at this.

I was able to reproduce locally. threshold_forces_commit_before_interval is flaky and can hang.

Comment thread crates/vector-store/src/fts_index/tantivy.rs
Comment thread crates/vector-store/src/fts_index/tantivy.rs Outdated
knowack1 added 2 commits July 23, 2026 14:12
Before, the fixture created the index and documents
were added to the created index. In this scenario, the index had to search
and poll until expected results.
Now the index is created after documents are added and before proceeding
with the test, we wait until the index is built. This also more properly
validates the index readinessimplementation.

The crud tests verify that the index also properly handles post-built
updates.
Test case that adds 10k documents to the FTS index and runs a search
query to validate that the index is working correctly.

Measure (but do not assert) the time it takes to index the documents
and run the search query.

Fixes VECTOR-636
@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch 2 times, most recently from a152c48 to a8304de Compare July 23, 2026 12:24
@knowack1

knowack1 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

I fixed the flaky test. The problem was a race condition: the timer was being reset before spawning the task that actually adds the document to the writer. As a result, the timer handler could run before the spawned task, committing no documents.

I changed the approach and dropped the timer reset altogether. Instead, I now commit immediately after the add/remove handlers inside the same spawned task.

This change was introduced in a dedicated commit: 515f882.

@ewienik could you please share you opinion?

@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch from a8304de to 515f882 Compare July 23, 2026 12:38
@ewienik

ewienik commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

I fixed the flaky test. The problem was a race condition: the timer was being reset before spawning the task that actually adds the document to the writer. As a result, the timer handler could run before the spawned task, committing no documents.

I changed the approach and dropped the timer reset altogether. Instead, I now commit immediately after the add/remove handlers inside the same spawned task.

This change was introduced in a dedicated commit: 515f882.

@ewienik could you please share you opinion?

Changes seems ok. Could you combine them with the correct previous commit to stick with single implementation in the PR?

knowack1 added 2 commits July 23, 2026 15:56
Previously, every AddDocument/RemoveDocument operation triggered an
immediate tantivy commit and reader reload, which was very slow; the
indexing of 10k small documents was taking 2 minutes.

Replace the per-operation commit with a periodic tick (every 3s by
default) driven by a tokio::select! loop.
Additionally index tracks number of uncommitted documents and triggers
the commit when documents exceeds 10k threshold.
This prevents from unlimited growth of uncommitted documents.

VECTOR-621
By default Tantivy reader is configured to auto reload after
commit after some delay. Disable Tantivy auto reload as we
call it manually. We need to call this manually so that we
correctly notify by dropping the InProgress guard that documents have
been processed and can be searchable.
@knowack1
knowack1 force-pushed the vector-636-large-set-test-case branch from 515f882 to 0ae51c9 Compare July 23, 2026 13:57
@knowack1

Copy link
Copy Markdown
Collaborator Author

I fixed the flaky test. The problem was a race condition: the timer was being reset before spawning the task that actually adds the document to the writer. As a result, the timer handler could run before the spawned task, committing no documents.
I changed the approach and dropped the timer reset altogether. Instead, I now commit immediately after the add/remove handlers inside the same spawned task.
This change was introduced in a dedicated commit: 515f882.
@ewienik could you please share you opinion?

Changes seems ok. Could you combine them with the correct previous commit to stick with single implementation in the PR?

Done.

@ewienik
ewienik added this pull request to the merge queue Jul 23, 2026
Merged via the queue into scylladb:master with commit 27512be Jul 23, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants