Skip to content

feat(suggest): add autocomplete / as-you-type suggest endpoint#113

Merged
poyrazK merged 12 commits into
mainfrom
feature/autocomplete-suggest
Jun 10, 2026
Merged

feat(suggest): add autocomplete / as-you-type suggest endpoint#113
poyrazK merged 12 commits into
mainfrom
feature/autocomplete-suggest

Conversation

@poyrazK

@poyrazK poyrazK commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add , , types to cloudsearch-common
  • Create with , , for in-memory autocomplete
  • Create for binary file read/write during flush/merge
  • Add field to , build suggest index during flush
  • Add API endpoint with multi-field support
  • Binary search for O(log n + m) prefix lookup achieving sub-10ms latency
  • Score = doc_freq / n_docs for popularity-based ranking

API

Request:

{
  "prefix": "elast",
  "fields": {"title": 1.0, "description": 0.5},
  "size": 10
}

Response:

{
  "suggestions": [
    {"text": "elastic", "score": 0.5, "doc_freq": 10, "field": "title"},
    {"text": "elasticsearch", "score": 0.25, "doc_freq": 5, "field": "title"}
  ]
}

Performance

  • O(log n + m) lookup via sorted term array + binary search
  • In-memory data structures, no disk I/O on query path
  • Sub-10ms achievable for interactive autocomplete

poyrazK added 2 commits June 9, 2026 20:11
- Add SuggestRequest, SuggestResponse, Suggestion types to cloudsearch-common
- Create suggest_index.rs with SuggestIndex, SuggestEntry, SuggestReader
- Create suggest_writer.rs for binary file read/write
- Add suggest_readers field to IndexHandle, build suggest index during flush
- Add POST /{index}/_suggest API endpoint with multi-field support
- Binary search for O(log n + m) prefix lookup
- Score = doc_freq / n_docs for popularity-based ranking
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@poyrazK, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 2 minutes and 46 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8a6d92da-a948-4555-8b2e-10bbe095ff4c

📥 Commits

Reviewing files that changed from the base of the PR and between f5bf9e6 and 8beb4fc.

📒 Files selected for processing (10)
  • docs/adr/0004-autocomplete-suggest-index.md
  • docs/api-v1.md
  • rust/crates/cloudsearch-api/src/lib.rs
  • rust/crates/cloudsearch-common/src/lib.rs
  • rust/crates/cloudsearch-index/src/lib.rs
  • rust/crates/cloudsearch-node/tests/api_smoke.rs
  • rust/crates/cloudsearch-node/tests/helpers.rs
  • rust/crates/cloudsearch-storage/src/lib.rs
  • rust/crates/cloudsearch-storage/src/suggest_index.rs
  • rust/crates/cloudsearch-storage/src/suggest_writer.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/autocomplete-suggest

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

poyrazK added 10 commits June 9, 2026 20:15
- doc_freq: count unique docs per term, not token occurrences
  Use BTreeSet<doc_id> per term per field in build_suggest_index
  to deduplicate within each document before counting.
  Fix: 'foo foo foo' + 'foo bar' → doc_freq('foo') = 2, not 4.

- NaN panic: replace .unwrap() with .unwrap_or(Ordering::Equal)
  in suggest() sort comparator. NaN scores now sort to equality
  instead of panicking.

- Stale suggest_readers: reload all suggest sidecar readers
  in apply_merge_plan after manifest update, mirroring the
  positions_readers reload pattern. Prevents stale readers
  pointing to non-existent sidecar files after a merge.

- Empty prefix: return Vec::new() for empty prefix in
  suggest_for_field(). Previously '' returned the entire
  vocabulary via starts_with('').

- docs: add POST /{index}/_suggest to api-v1.md with request/
  response shapes and implementation notes.

- docs: add ADR 0004 for the autocomplete suggest index design.

@poyrazK poyrazK left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

It's okay to merge

@poyrazK poyrazK merged commit 2be8ac8 into main Jun 10, 2026
4 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.

1 participant