Skip to content

perf: reuse prepared RAG retriever across requests - #619

Merged
sng-asyncfunc merged 1 commit into
AsyncFuncAI:mainfrom
sometimecry:perf/cache-rag-retriever
Nov 4, 2026
Merged

sng-asyncfunc merged 1 commit into
AsyncFuncAI:mainfrom
sometimecry:perf/cache-rag-retriever

Conversation

@sometimecry

Copy link
Copy Markdown
Contributor

Problem
prepare_repo_index() creates a new RAG instance per request. Each construction reloads the LocalDB pickle and rebuilds the FAISS index — slow and memory-hungry for large repositories; consecutive requests can accumulate enough memory to OOM-kill the process.

Solution
Cache the prepared instance in a module-level dict keyed by repo/type/token/provider/model and include/exclude filters so repeated requests reuse one retriever.

Every request rebuilt the retriever from scratch (reload LocalDB, rebuild FAISS), which is slow and memory-hungry for large repos and can OOM during multi-page wiki generation. Cache the prepared RAG instance per repo/model/filter combination.
@sng-asyncfunc
sng-asyncfunc merged commit c1b0b26 into AsyncFuncAI:main Nov 4, 2026
sng-asyncfunc pushed a commit that referenced this pull request Nov 7, 2026
research_chat stored each request's prior turns in rag.memory. Since #619 the
RAG object is cached and shared, so turns leaked into other requests and
repeated on resend. Build the history from request.messages and remove the
now-unused Memory class.
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.

2 participants