feat: Add Retrieval Package with Chunk, Embed, and Vector Search - #14
Open
ThomasHartDev wants to merge 4 commits into
Open
feat: Add Retrieval Package with Chunk, Embed, and Vector Search#14ThomasHartDev wants to merge 4 commits into
ThomasHartDev wants to merge 4 commits into
Conversation
Recursive character chunking with overlap, a hashing-trick embedder, and cosine top-k search so the agent can ground answers on document context (RAG).
Track original spans through split/pack so chunk text is always a slice of the normalized document, and hard-split runs no longer pick up spaces from join-with-space packing.
Empty-separator splits now emit sliding windows (step size-overlap). packWithOverlap takes full size windows when the cursor is an overlap carry, so size-length pieces no longer abut with zero shared chars.
packWithOverlap advanced with next<=pos?end, which zeroed shared chars whenever a soft flush was shorter than or equal to overlap (lead-in before a long URL/run). Always progress by at least one code unit while retaining max overlap; cover with regression tests.
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.
Adds
@agent/retrieval: recursive text chunking with source-mapped offsets, hashing embedder, in-memory vector store, and a small Retriever for ingest/search/context formatting.Chunker guarantees (after CRLF normalize):
original.slice(start, end) === chunk.textoverlapis honored on default hard splits, size-length space-separated tokens, and short soft-packed lead-ins before long unbreakable tokens (shared === min(overlap, prevLen - 1))size - overlapAlso includes HashingEmbedder, cosine top-k InMemoryVectorStore, and Retriever.ingest/search + formatContext. Covered with vitest (empty input, hard splits + overlap, size-token packing, short soft lead-in + URL/run, source maps, ranking, e2e retrieve). typecheck, test, build, and format check are green locally.
Package is standalone for this PR; wiring into agent-core / apps/server is follow-up.