Skip to content

feat(retrieve): add keyword retriever option and per-call override#346

Open
jl1371-cell wants to merge 8 commits intoNevaMind-AI:mainfrom
jl1371-cell:feature/keyword-retriever
Open

feat(retrieve): add keyword retriever option and per-call override#346
jl1371-cell wants to merge 8 commits intoNevaMind-AI:mainfrom
jl1371-cell:feature/keyword-retriever

Conversation

@jl1371-cell
Copy link

What

  • Add RetrieveConfig.retriever option for RAG item recall: vector / keyword.
  • Support per-call override: MemoryService.retrieve(..., method=..., retriever=...).
  • Support wrapper-level default retriever in the OpenAI wrapper (set once at init).

Why

Keyword retriever provides a lightweight & explainable fallback, and enables deterministic matching when embeddings are unavailable.

Behavior (no breaking changes)

  • Default behavior unchanged: if users don’t pass retriever, RAG continues to use the default (vector).
  • Precedence:
    • per-call retriever (if provided) overrides RetrieveConfig.retriever
    • per-call method (if provided) overrides RetrieveConfig.method
  • Wrapper compatibility: when retriever is None, the wrapper does not forward retriever downstream (avoids errors if downstream service doesn’t accept this arg).

Implementation

  • RetrieveConfig gains retriever (normalized case-insensitively).
  • RetrieveMixin.retrieve accepts optional method/retriever; writes state["retriever"] for RAG workflows.
  • _rag_recall_items chooses keyword/vector based on state["retriever"].
  • OpenAI wrapper threads an optional default retriever; per-call still overrides.

Tests

  • make test
  • make check

Notes

  • Tests that require external API keys are conditionally skipped when related env vars are not set (e.g. OPENAI_API_KEY, OPENROUTER_API_KEY).

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.

3 participants