Skip to content

refactor: Accept tokens in GetPodScores#266

Open
acardace wants to merge 2 commits intollm-d:mainfrom
acardace:feat/getpodscores-tokens
Open

refactor: Accept tokens in GetPodScores#266
acardace wants to merge 2 commits intollm-d:mainfrom
acardace:feat/getpodscores-tokens

Conversation

@acardace
Copy link

Summary

Refactors GetPodScores to accept tokens []uint32 instead of renderReq and prompt parameters.

  • Adds Tokenize method to Indexer that returns ([]uint32, error)
  • Updates GetPodScores signature to accept tokens []uint32 directly
  • Propagates tokenization errors to callers instead of silently returning nil

Fixes #244

Copy link
Contributor

Copilot AI left a comment

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 refactors the GetPodScores method to accept pre-tokenized tokens rather than performing tokenization internally. This separation of concerns allows callers to handle tokenization errors explicitly and reuse tokens across multiple calls.

Changes:

  • Modified Tokenize method in pkg/tokenization/pool.go to return ([]uint32, error) instead of just tokens
  • Updated GetPodScores signature to accept tokens []uint32 and removed renderReq and prompt parameters
  • Added new Tokenize method to Indexer that wraps the tokenization pool's Tokenize method
  • Updated all callers to tokenize prompts before calling GetPodScores and handle tokenization errors
  • Enhanced test coverage for error handling in tokenization failures

Reviewed changes

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

Show a summary per file
File Description
pkg/tokenization/pool.go Modified Tokenize to return error, added error field to tokenizationResponse
pkg/tokenization/pool_test.go Updated tests to verify error handling and fixed benchmark to ignore return values
pkg/kvcache/indexer.go Refactored GetPodScores to accept tokens, added Tokenize wrapper method
tests/e2e/redis_mock/e2e_test.go Updated all test cases to tokenize before calling GetPodScores
examples/valkey_example/main.go Added tokenization step with error handling, reuses tokens across calls
examples/kv_events/online/main.go Added tokenization with proper error handling in HTTP handlers
examples/kv_events/offline/main.go Added tokenization step with error handling
examples/kv_cache_index_service/server/server.go Added tokenization in GetPodScores RPC handler
examples/kv_cache_index_service/server/main.go Added tokenization in main demo code
examples/kv_cache_index/main.go Added tokenization with error handling, reuses tokens
examples/kv_cache_aware_scorer/kvcache_aware_scorer.go Added tokenization in Score method with error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@acardace acardace force-pushed the feat/getpodscores-tokens branch from 5226b29 to c671aba Compare January 21, 2026 14:23
Change GetPodScores signature to accept tokens
instead of handling tokenization internally.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
Signed-off-by: Antonio Cardace <acardace@redhat.com>
@acardace acardace force-pushed the feat/getpodscores-tokens branch from c671aba to cc03a33 Compare January 21, 2026 14:29
@github-actions
Copy link

This PR is marked as stale after 21d of inactivity. After an additional 14d of inactivity (7d to become rotten, then 7d more), it will be closed. To prevent this PR from being closed, add a comment or remove the lifecycle/stale label.

res := <-resultCh
tokens := res.Tokens
return tokens
if res.Err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think return res.Tokens, res.Err should be enough

traceLogger.Info("Both chat/completions and completions present; defaulting to chat/completions")
}

renderReq := &preprocessing.ApplyChatTemplateRequest{
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that the chat template is lost with this refactoring.

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.

Update GetPodScores of Indexer to get tokens as an input instead of preprocessing.RenderJinjaTemplateRequest

3 participants