feat(ollama): return real token counts from embedding endpoint#11
Merged
Conversation
- Switch from deprecated /api/embeddings to /api/embed
- generateEmbedding() now returns EmbeddingResult { embedding, promptTokens }
instead of plain number[] — promptTokens comes from prompt_eval_count
- Add OllamaAdapter.embed() convenience method
- Update live tests to verify promptTokens > 0
- Update README with new return type and adapter example
BREAKING CHANGE: generateEmbedding() return type changed from
Promise<number[]> to Promise<EmbeddingResult>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Ollama's
/api/embedendpoint returnsprompt_eval_count(input token count) but agentic-kit was discarding it. This PR:/api/embeddingsto/api/embed— the newer endpoint supports batch input and returnsprompt_eval_countgenerateEmbedding()now returnsEmbeddingResultinstead ofnumber[]:OllamaAdapter.embed()convenience method that delegates to the clientBREAKING CHANGE:
generateEmbedding()return type changed fromPromise<number[]>toPromise<EmbeddingResult>. Callers need to useresult.embeddinginstead of the raw array.Before:
After:
This unblocks constructive's metering layer from using real token counts for embeddings (currently using ~4 chars/token placeholder).
Review & Testing Checklist for Human
nomic-embed-textinstalled:OLLAMA_LIVE_MODEL=qwen3.5:4b pnpm --filter @agentic-kit/ollama test:live:extended— verifypromptTokens > 0in the new embedding tests/api/embedendpoint works with your Ollama version (requires Ollama ≥ 0.4.0 for/api/embed; older versions only have/api/embeddings)generateEmbedding()— they need to update fromresult(array) toresult.embedding(array) and can now accessresult.promptTokensNotes
agentic-kitpackage test failure (reasoningfield mismatch withProviderAdaptertype) is unrelated — same failure on main/api/embeddingsendpoint (singular) returned{ embedding: number[] }. The new/api/embedreturns{ embeddings: number[][], prompt_eval_count: number }— we takeembeddings[0]for single-text inputLink to Devin session: https://app.devin.ai/sessions/2b5a29d83d3f478e8d3d972653b4879c
Requested by: @pyramation