Skip to main content
CodebaseMemory is a thin client over the rb-api /findings/... endpoints. It lets an agent persist observations during a run — bug locations, behavioral notes, architectural patterns — and recall them semantically on future runs. All transport errors are caught and surface as empty results / None / 0, so a missing rb-api never breaks the agent loop.

Initialize

Constructor signature:
str
required
Required. Identifier the findings are scoped under. Common patterns: org/repo, repo@sha:abc123. All findings stored under the same id are searchable together.
str
required
Sent as Authorization: Bearer <api_key> on every request.
str
default:"DEFAULT_BASE_URL"
Override to point at a self-hosted rb-api. Trailing slashes are stripped.
float
default:"DEFAULT_TIMEOUT"
HTTP timeout passed to the underlying httpx.Client.
Pass the same codebase_id to CodebaseMemory and to rb.middleware(codebase_id=...) if you also use the middleware — the middleware uses it to scope E1 retrieval.

Store and recall

Store a finding

Returns the finding id on success or None on transport error. Content is truncated server-side at 8000 chars; file_path at 512; finding_type at 64.

Recall by query

Returns a list of {content, file_path, finding_type, score, ...} dicts ordered by descending score. Raise score_threshold for tighter matches; lower it for more recall.

Pre-formatted recall (for tool outputs)

format_recall combines recall with a human-readable renderer. Use it when a tool needs to return findings as a string.
Returns "(no relevant findings in cache yet)" when nothing matches.

Other operations

List every finding

Useful for auditing the cache before a run.

Batch store

Each dict needs at least content. file_path, finding_type, and metadata are optional. Returns the count actually stored (entries that fail or have empty content are skipped).

Coverage check

coverage_for returns the fraction of a file list that has at least one stored finding. A soft suffix-match means a stored pydantic/main.py covers a query for bare main.py.

Invalidate stale findings

When files change, drop their findings:
Returns the number deleted server-side.

Clear the entire cache

clear() cannot be undone. Use invalidate() for targeted cleanups.

Release the HTTP client

CodebaseMemory holds a persistent httpx.Client to keep TCP connections warm across calls. Call close() when you’re done if your process needs to release sockets cleanly.

Pair with ImportGraph for blast-radius invalidation

When a file changes, you usually want to invalidate every file that imports it. ImportGraph (see Import graph) gives you the blast radius:
ImportGraph.build_from_files requires networkx. Install with pip install networkx.

Wire into your agent

Each framework has a tool factory wrapping CodebaseMemory (and optionally ImportGraph). See:
  • LangChain tools via make_langchain_tools
  • OpenAI Agents tools via make_openai_tools
  • reasonblocks.integrations.claude_tools.make_claude_tools for the Anthropic Messages API