Skip to content

feat(embedding): return token limit details in the error - #21

Merged
HarshMN2345 merged 2 commits into
masterfrom
fix-embedding-too-long-error
Nov 18, 2026
Merged

HarshMN2345 merged 2 commits into
masterfrom
fix-embedding-too-long-error

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

Follow-up to #20.

What changed

Text over the token limit still returns 400, and error is now an object so callers can tell it apart from other 400s and find the text:

{"error":{"type":"text_too_long","message":"text at index 1 has 20002 tokens, the limit for nomic-embed-text is 2048","index":1,"tokens":20002,"limit":2048}}

Other errors keep the {"error":"message"} shape.

Testing

cargo fmt, cargo clippy, 26 unit tests and 10 ignored e2e tests pass. The response was also checked through Appwrite's POST /v1/embeddings/text running against this build.

@appwrite

appwrite Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Text-over-limit errors now retain the offending text index, token count, and limit, and the HTTP endpoint returns those details in a typed error object. Other error responses continue to use the existing string-valued error field.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 5
File Change
README.md Documents the structured text-too-long error response.
src/embedding.rs Populates structured details when tokenization finds an over-limit text.
src/error.rs Represents text-too-long errors with model, index, token count, and limit fields.
src/main.rs Serializes text-too-long failures as a typed JSON error while preserving other error shapes.
tests/embed_e2e.rs Updates over-limit error variant assertions for the structured variant.

Reviewed e98bbfd · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot 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.

🟢 Tier S · Looks good to merge. Summary

@HarshMN2345
HarshMN2345 merged commit 213a7fa into master Nov 18, 2026
4 checks passed
@github-actions

Copy link
Copy Markdown

Memory benchmark

Base c3dc1bb vs head e98bbfd on ubuntu-latest.

Model nomic, EMBEDDING_POOL_SIZE=1, 12 requests of 16 texts (100 to 1,800 words), median of 2 runs. Retained is RSS 3s after the last request.

Concurrent requests Peak (base) Peak (head) Δ Retained (base) Retained (head) Δ Time (base) Time (head)
1 5217 MB 5215 MB -0% 590 MB 588 MB -0% 253.2s 255.7s
4 5218 MB 5220 MB +0% 591 MB 590 MB -0% 256.8s 246.8s

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