embedder: guard against long inputs by chunking, batching and averaging#1487
Open
Yuyuyaka wants to merge 2 commits into
Open
embedder: guard against long inputs by chunking, batching and averaging#1487Yuyuyaka wants to merge 2 commits into
Yuyuyaka wants to merge 2 commits into
Conversation
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.
Title: embedder: guard against long inputs by chunking, batching and averaging
Summary
This patch makes the OpenAI-based embedder resilient to very long text inputs
that previously triggered provider token-limit errors (causing 500s). It adds
character-based chunking, batching and averaging of per-chunk embeddings as a
safe default, and includes a minimal
Dockerfileso maintainers can reproduceand publish a patched image.
What changed
OpenAIEmbedder.createnow:strinputs into roughlyDEFAULT_MAX_INPUT_CHARScharacters,representation,
create_batchdelegates tocreate()so each item is guarded.docker/Dockerfile+build_image.shfor a reproducible local image.Why
Long messages (> provider token limit) caused the upstream embedding API to
reject requests and Graphiti to return 500, which cascaded to OpenClaw gateway
timeouts. This change prevents oversized inputs from being forwarded directly
to the provider and provides a conservative, backwards-compatible default.
Testing done
patched
openai.pyand restarting:POST /get-memorywith ~20k chars nowreturns HTTP 200 and does not raise embedding errors.
docker build(taggraphiti-local:embedder-chunking-20260512).How to review
openai.pyimplementation for correctness and style.whether the code should instead store multiple per-chunk embeddings and
change retrieval logic.
Notes for maintainers
more sophisticated summarization before embedding, or token-aware chunking.