Skip to content

feat: Add Retrieval Package with Chunk, Embed, and Vector Search - #14

Open
ThomasHartDev wants to merge 4 commits into
mainfrom
thomas/feat/retrieval
Open

feat: Add Retrieval Package with Chunk, Embed, and Vector Search#14
ThomasHartDev wants to merge 4 commits into
mainfrom
thomas/feat/retrieval

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

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):

  • every chunk satisfies original.slice(start, end) === chunk.text
  • default separators never inject spaces into hard-split unbreakable runs
  • configured overlap is 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))
  • empty-separator fallback uses sliding windows with step size - overlap

Also 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.

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.
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