Skip to content

feat: add FlowRAG workflow memory & retrieval module with ChromaDB baโ€ฆ#3049

Open
ardi1s wants to merge 1 commit into
charmbracelet:mainfrom
ardi1s:feat/flowrag
Open

feat: add FlowRAG workflow memory & retrieval module with ChromaDB baโ€ฆ#3049
ardi1s wants to merge 1 commit into
charmbracelet:mainfrom
ardi1s:feat/flowrag

Conversation

@ardi1s
Copy link
Copy Markdown

@ardi1s ardi1s commented Jun 1, 2026

Summary

Adds FlowRAG, an intelligent workflow memory and retrieval module to Crush.
It captures successful multi-step tool call sequences, stores them in a
ChromaDB vector database, and retrieves similar past workflows via semantic
search to accelerate future tasks.

How It Works

Trigger Detection (Dual Layer)

Primary โ€” Skill-driven: FlowRAG registers as a built-in Skill
(internal/skills/builtin/flowrag/SKILL.md). The LLM automatically
identifies when to trigger it โ€” when a multi-step task completes
without errors, when the user confirms satisfaction, or when the
user explicitly asks to save a workflow.

Secondary โ€” Keyword matching: CompletionDetector recognizes explicit
markers ("task complete", "save workflow", "remember this") alongside
colloquial confirmation phrases ("ok", "ๆžๅฎšไบ†", "done").

Data Flow

Task completed โ†’ prompt "Save workflow? (y/n)"
โ†’ y: Segmenter extracts successful steps, skipping IsError retries
โ†’ Embedding generated via OpenAI-compatible API or local trigram hash
โ†’ Stored in ChromaDB collection "crush_workflows"
โ†’ Next similar task: semantic search retrieves Top-K
โ†’ Retrieved workflows injected as system prompt context

Embedding Strategy

Two embedding backends:

  • OpenAIEmbeddingClient: calls any OpenAI-compatible /embeddings endpoint
    (e.g. text-embedding-3-small, DeepSeek, Ollama)
  • HashEmbeddingClient: zero-dependency trigram-hash embedding that
    produces content-aware vectors locally โ€” no API key required

Vector Storage

VectorStoreBackend interface with two implementations:

  • ChromaDBStore: REST API v2 client, auto-creates "crush_workflows"
    collection on first use
  • JSONFileStore: local JSON file persistence, zero external dependencies,
    used as automatic fallback when ChromaDB is unavailable

Changes

internal/flowrag/
โ”€โ”€ detector.go Completion marker detection (Skill + keyword)
โ”€โ”€ segmenter.go Workflow segmentation with error-step filtering
โ”€โ”€ store.go Vector store interface, ChromaDB + JSON backends,
OpenAI + Hash embedding clients
โ”€โ”€ retriever.go Semantic search + system prompt context builder
โ”€โ”€ workflow.go Orchestrator with unified public API
โ”€โ”€ workflow_test.go 17 unit tests covering all components
โ”€โ”€ cmd/demo/main.go Interactive CLI demo with trigram-hash embeddings
(zero-dependency, runs without any API key)
โ”€โ”€ cmd/e2e_test/main.go End-to-end semantic search verification script
โ””โ”€โ”€ README.md Full English documentation

internal/skills/builtin/flowrag/SKILL.md
Built-in Skill definition โ€” LLM autoloads this to know when FlowRAG
should trigger. Describes save/retrieve protocol, ChromaDB config,
and E2E testing procedure.

.gitignore
Added crush.local.json and flowrag_workflows.json to prevent
accidental credential / local data leaks.

Testing

Unit Tests

$ go test ./internal/flowrag/... -count=1 -v

PASS: TestCompletionDetector_Match (15 sub-cases)
PASS: TestTaskCompleteMarker (6 business keyword cases)
PASS: TestShouldTriggerFlowRAG
PASS: TestSegmenter_SuccessfulFlow
PASS: TestSegmenter_ExcludeErrorSteps
PASS: TestWorkflow_ToText
PASS: TestJSONFileStore_InsertAndSearch
PASS: TestJSONFileStore_SearchEmpty
PASS: TestCosineSimilarity (4 precision checks)
PASS: TestRetriever_BuildContextPrompt
PASS: TestRetriever_BuildContextPromptEmpty
PASS: TestWorkflowManager_Integration
PASS: TestTruncate
PASS: TestMustMarshalSteps

17 tests, all passing. Covers: detector, segmenter, both store
backends, cosine similarity precision, retriever, end-to-end
integration.

E2E Semantic Search

$ go run ./internal/flowrag/cmd/e2e_test/

Inserts 6 cross-domain workflows (auth fix, REST API, Python CSV
parser, DB migration, OAuth refresh, Docker Compose) then runs
semantic queries:

"fix a login authentication bug" โ†’ #1 auth-login-fix โœ“
"python parse csv data" โ†’ #1 python-csv-parser โœ“
"user registration API endpoint" โ†’ #1 rest-api-register โœ“
"database migration SQL" โ†’ #1 db-migration โœ“
"OAuth token refresh expired" โ†’ #1 oauth-token-refresh โœ“

Interactive Demo

$ go run ./internal/flowrag/cmd/demo/

Fully interactive CLI demo using the HashEmbeddingClient (zero
API key required). Demonstrates insert/search/list operations
with natural language queries.

All existing tests continue to pass โ€” no modifications to
existing code paths outside the new package.

gofmt / go vet: clean

@charmcli
Copy link
Copy Markdown
Contributor

charmcli commented Jun 1, 2026

All contributors have signed the CLA โœ๏ธ โœ…
Posted by the CLA Assistant Lite bot.

@ardi1s
Copy link
Copy Markdown
Author

ardi1s commented Jun 1, 2026

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

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