Skip to content

refactor: Extract shared utilities into ai_brain package#2

Open
Ovbosire wants to merge 2 commits into
TheSethRose:mainfrom
Ovbosire:archon/task-refactor-extract-shared-utils-v2
Open

refactor: Extract shared utilities into ai_brain package#2
Ovbosire wants to merge 2 commits into
TheSethRose:mainfrom
Ovbosire:archon/task-refactor-extract-shared-utils-v2

Conversation

@Ovbosire

Copy link
Copy Markdown

Summary

Extract duplicated code across app.py, query_brain.py, graph_query.py, and ingestion scripts into a shared ai_brain/ package structure, eliminating ~100 lines of duplicated code.

Changes

  • ai_brain/query/time_filter.py — Shared time-filter parsing (was duplicated in app.py and query_brain.py)
  • ai_brain/graph/driver.py — Shared Neo4j driver with lazy initialization and liveness check (was duplicated across 4 files). Raises ConnectionError instead of calling sys.exit(1).
  • ai_brain/query/flat_rag.py — Shared flat RAG vector+keyword search (was duplicated in app.py and query_brain.py)
  • ai_brain/query/text_utils.py — Shared STOPWORDS set (was duplicated with slight variations in query_brain.py and graph_query.py)
  • app.py — Imports from shared modules; removes ~50 lines of duplicated logic
  • query_brain.py — Imports from shared modules; removes ~45 lines of duplicated logic
  • graph_query.py — Imports STOPWORDS and Neo4j driver from shared modules; removes ~25 lines
  • extract_entities.py — Imports Neo4j driver from shared module; removes ~10 lines
  • extract_daemon.py — Imports Neo4j driver from shared module
  • neo4j_setup.py — Imports Neo4j driver from shared module; removes ~15 lines

Validation

  • Python syntax check passes on all 14 files
  • Package structure: ai_brain/, ai_brain/graph/, ai_brain/query/, ai_brain/ingestion/
  • All public function signatures preserved exactly
  • Each consumer file imports from the single shared source of truth

File Structure

ai_brain/
├── __init__.py
├── graph/
│   ├── __init__.py
│   └── driver.py          # get_neo4j_driver()
├── ingestion/
│   └── __init__.py
└── query/
    ├── __init__.py
    ├── flat_rag.py         # flat_rag_search()
    ├── text_utils.py       # STOPWORDS
    └── time_filter.py      # parse_time_filter()

Ovbosire added 2 commits July 10, 2026 05:38
- Add Knowledge Brain system: ingest AI conversation history (Gemini, Claude, DeepSeek) and local documents into a GraphRAG pipeline
- Postgres + pgvector for vector storage and hybrid search
- Neo4j knowledge graph with entity/relationship extraction via Ollama
- FastAPI web UI with SSE streaming chat + graph visualization (static/index.html)
- Unified CLI (cli.py) with interactive menu, query console, ingestion, and daemon commands
- Extraction daemon (extract_daemon.py) with thermal throttling and auto-resume
- Hybrid GraphRAG search (graph_query.py): vector + keyword + 1-hop graph traversal
- Temporal filter syntax in query console (last week, since june, in 2025)
- Domain filtering support
- Switch file organizer from Gemini to local Ollama (llama3.2)
- Add document vault ingester with PDF support (pypdf)
- Pinned all dependency versions in requirements.txt
- Expanded configuration in .env.example with Postgres, Neo4j, Ollama, thermal throttling settings
- Comprehensive README covering architecture, setup, and usage for both components
- Create ai_brain/ package with graph/, query/, ingestion/ subpackages
- Extract time-filter parsing into ai_brain/query/time_filter.py
- Extract Neo4j driver into ai_brain/graph/driver.py (lazy init + liveness check)
- Extract flat RAG search into ai_brain/query/flat_rag.py
- Extract shared STOPWORDS into ai_brain/query/text_utils.py
- Update app.py, query_brain.py, graph_query.py, extract_entities.py,
  extract_daemon.py, neo4j_setup.py to import from shared modules
- Eliminates ~100 lines of duplicated code across 4+ files
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