Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

12 Commits

Folders and files

Repository files navigation

🧠 Second Brain - AI-Powered Knowledge Management System

Python 3.8+ Neo4j License: MIT

An intelligent knowledge management system that automatically processes, understands, and connects your documents using AI. Built with a production-grade agentic architecture, vector search, and knowledge graphs.

✨ Features

πŸ€– Intelligent Processing Pipeline

  • Automated Document Ingestion: Drop PDFs into the inbox folder and watch them get processed automatically
  • Multi-Step Agent Architecture: Coordinated agents handle extraction, summarization, tagging, and embedding
  • Smart Chunking: Documents are intelligently split while preserving context
  • AI-Powered Summarization: Get concise summaries using local LLMs via Ollama

πŸ” Advanced Search & Retrieval

  • Semantic Search: Find documents by meaning, not just keywords
  • Hybrid Retrieval: Combines vector similarity and knowledge graph traversal
  • Context-Aware Answers: Get relevant answers with supporting evidence
  • Multi-Step Reasoning: AI agent performs step-by-step reasoning over your knowledge base

πŸ•ΈοΈ Knowledge Graph

  • Automatic Relationship Discovery: Connects documents through shared topics and concepts
  • Graph-Based Exploration: Navigate your knowledge through conceptual links
  • Topic Clustering: Automatically categorizes content by topics, concepts, and applications

πŸ“Š AI Insights

  • Knowledge Analytics: Discover patterns across your entire knowledge base
  • Recommendation Engine: Get personalized document recommendations
  • Insight Generation: AI-powered insights about your learning journey

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    File Watcher (Inbox)                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Agent Orchestrator (Planner)                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Extract β”‚β†’β”‚ Summarizeβ”‚β†’β”‚   Tag    β”‚β†’β”‚  Embed   β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                   β”‚                          β”‚
β”‚                                   β–Ό                          β”‚
β”‚                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚                        β”‚  Graph Builder   β”‚                 β”‚
β”‚                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Storage Layer                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  ChromaDB   β”‚    β”‚   Neo4j     β”‚    β”‚ File System  β”‚   β”‚
β”‚  β”‚ (Vectors)   β”‚    β”‚  (Graph)    β”‚    β”‚ (Processed)  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Query Agent                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ Retrieve β”‚β†’β”‚   Tag    β”‚β†’β”‚  Graph   β”‚β†’β”‚  Reason  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Prerequisites

Required Software

  • Python 3.8+
  • Neo4j 5.0+ - Graph database for knowledge relationships
  • Ollama - Local LLM inference engine

System Requirements

  • 8GB RAM minimum (16GB recommended)
  • 10GB free disk space for models and data
  • macOS, Linux, or Windows (WSL recommended)

πŸ“¦ Installation

1. Clone the Repository

git clone https://github.com/yourusername/second-brain.git
cd second-brain

2. Set Up Python Environment

# Create virtual environment
python -m venv .venv

# Activate virtual environment
# On macOS/Linux:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

3. Install Neo4j

# macOS (using Homebrew)
brew install neo4j
neo4j start

# Linux/Windows - Download from https://neo4j.com/download/

4. Install Ollama

# macOS/Linux
curl -fsSL https://ollama.com/install.sh | sh

# Pull the required model
ollama pull llama3.2:3b

5. Configure Environment Variables

# Create .env file
cp .env.example .env

# Edit .env with your settings

.env file:

# Ollama Model
MODEL_NAME=llama3.2:3b

# Neo4j Configuration
URI=bolt://localhost:7687
USERNAME=neo4j
PASSWORD=your_secure_password_here

6. Set Neo4j Password

# First time setup - reset password
neo4j-admin set-initial-password your_secure_password_here

πŸš€ Usage

Start the Processing Pipeline

# Activate virtual environment
source .venv/bin/activate

# Start the pipeline
python run_pipeline.py

The pipeline will:

  1. Monitor data/inbox/ for new PDF files
  2. Automatically process them through the AI pipeline
  3. Store embeddings, summaries, and graph relationships
  4. Move processed files to data/processed/

Query Your Knowledge Base

# Interactive query interface
python -m src.scripts.query

Example queries:

Ask anything: What is machine learning?
Ask anything: Explain neural networks
Ask anything: What concepts relate to deep learning?

View AI Insights

# Generate insights about your knowledge base
python -m src.scripts.insights

Reset/Clean Database

# Clear all data and start fresh
python -m src.scripts.reset

πŸ“ Project Structure

second-brain/
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ inbox/              # Drop PDF files here for processing
β”‚   β”œβ”€β”€ processed/          # Processed files and metadata
β”‚   β”œβ”€β”€ archive/            # Archived files
β”‚   └── db/                 # ChromaDB vector database
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agent/              # Agentic orchestration
β”‚   β”‚   β”œβ”€β”€ executor.py     # Step execution engine
β”‚   β”‚   β”œβ”€β”€ orchestrator.py # Main orchestration loop
β”‚   β”‚   β”œβ”€β”€ planner.py      # Planning logic
β”‚   β”‚   └── query/          # Query agent components
β”‚   β”‚
β”‚   β”œβ”€β”€ processing/         # Document processing
β”‚   β”‚   β”œβ”€β”€ chunker.py      # Text chunking logic
β”‚   β”‚   β”œβ”€β”€ embeddings.py   # Vector embeddings
β”‚   β”‚   β”œβ”€β”€ summarizer.py   # AI summarization
β”‚   β”‚   └── tagger.py       # Topic/concept extraction
β”‚   β”‚
β”‚   β”œβ”€β”€ graph/              # Knowledge graph
β”‚   β”‚   β”œβ”€β”€ graph_builder.py
β”‚   β”‚   β”œβ”€β”€ graph_db.py     # Neo4j interface
β”‚   β”‚   └── graph_query.py  # Graph queries
β”‚   β”‚
β”‚   β”œβ”€β”€ memory/             # Vector storage
β”‚   β”‚   └── vector_store.py # ChromaDB interface
β”‚   β”‚
β”‚   β”œβ”€β”€ retrieval/          # Search & retrieval
β”‚   β”‚   β”œβ”€β”€ search.py       # Semantic search
β”‚   β”‚   β”œβ”€β”€ ranker.py       # Result ranking
β”‚   β”‚   └── qa.py           # Question answering
β”‚   β”‚
β”‚   β”œβ”€β”€ intelligence/       # AI insights
β”‚   β”‚   β”œβ”€β”€ ai_insights.py
β”‚   β”‚   β”œβ”€β”€ reasoning.py
β”‚   β”‚   └── recommender.py
β”‚   β”‚
β”‚   β”œβ”€β”€ tools/              # Reusable tools
β”‚   β”‚   β”œβ”€β”€ base_tool.py    # Tool interface
β”‚   β”‚   β”œβ”€β”€ extract.py      # PDF extraction
β”‚   β”‚   β”œβ”€β”€ summarize.py    # Summarization tool
β”‚   β”‚   β”œβ”€β”€ tag.py          # Tagging tool
β”‚   β”‚   β”œβ”€β”€ embed.py        # Embedding tool
β”‚   β”‚   β”œβ”€β”€ graph.py        # Graph tool
β”‚   β”‚   └── reason.py       # Reasoning tool
β”‚   β”‚
β”‚   β”œβ”€β”€ scripts/            # Utility scripts
β”‚   β”‚   β”œβ”€β”€ query.py        # Interactive query
β”‚   β”‚   β”œβ”€β”€ insights.py     # Insights dashboard
β”‚   β”‚   └── reset.py        # Database reset
β”‚   β”‚
β”‚   β”œβ”€β”€ ingestion/          # File ingestion
β”‚   β”‚   β”œβ”€β”€ watcher.py      # File system watcher
β”‚   β”‚   β”œβ”€β”€ worker.py       # Processing worker
β”‚   β”‚   └── queue_manager.py
β”‚   β”‚
β”‚   β”œβ”€β”€ state/              # State management
β”‚   β”‚   └── processing_state.py
β”‚   β”‚
β”‚   β”œβ”€β”€ utils/              # Utilities
β”‚   β”‚   └── hashing.py
β”‚   β”‚
β”‚   └── config.py           # Configuration
β”‚
β”œβ”€β”€ logs/                   # Application logs
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ run_pipeline.py         # Main entry point
β”œβ”€β”€ .env                    # Environment variables
β”œβ”€β”€ .gitignore
└── README.md

πŸ› οΈ Development

Code Quality Standards

This project follows production-level standards:

  • Type hints: All functions use Python type hints
  • Logging: Comprehensive logging with different levels
  • Error handling: Graceful error handling with detailed messages
  • Modularity: Clean separation of concerns
  • Documentation: Inline comments and docstrings

Adding New Tools

Tools follow the BaseTool interface:

from src.tools.base_tool import BaseTool

class MyCustomTool(BaseTool):
    name = "my_tool"
    description = "What this tool does"
    
    def run(self, *args, **kwargs):
        # Your logic here
        return {
            "result": "data",
            "metadata": {}
        }

The execute() method automatically wraps responses with:

  • Status tracking
  • Error handling
  • Execution time
  • Metadata

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=src

πŸ› Troubleshooting

Common Issues

1. Neo4j Authentication Error

Error: Neo.ClientError.Security.Unauthorized

Solution:

# Reset Neo4j password
neo4j-admin set-initial-password your_new_password

# Update .env file with new password

2. Ollama Model Not Found

Error: model 'llama3.2:3b' not found

Solution:

ollama pull llama3.2:3b

3. ChromaDB Permission Error

Error: Permission denied: data/db/chroma.sqlite3

Solution:

# Fix permissions
chmod -R 755 data/db/

4. PDF Extraction Fails

Error: No text extracted from file

Solution:

  • Ensure PDF is not scanned/image-based
  • Try OCR preprocessing if needed
  • Check PDF file is not corrupted

Logs

All logs are stored in logs/pipeline.log:

# View logs in real-time
tail -f logs/pipeline.log

# Search for errors
grep ERROR logs/pipeline.log

πŸ“Š Performance Tips

  1. Batch Processing: Process multiple files by dropping them all at once
  2. GPU Acceleration: Use Ollama with GPU for faster inference
  3. Chunk Size: Adjust chunk size in src/processing/chunker.py based on your use case
  4. Vector Index: ChromaDB automatically optimizes indexes
  5. Neo4j Tuning: Increase heap size for large knowledge bases

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 style guide
  • Add tests for new features
  • Update documentation
  • Keep commits atomic and well-described

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Ollama - Local LLM inference
  • Neo4j - Graph database
  • ChromaDB - Vector database
  • Sentence Transformers - Embedding models
  • Rich - Beautiful terminal output

πŸ—ΊοΈ Roadmap

  • Web interface (FastAPI + React)
  • Multi-format support (DOCX, TXT, Markdown)
  • Collaborative knowledge bases
  • Cloud deployment guides
  • Integrations (Notion, Obsidian)
  • Mobile app
  • Real-time collaboration
  • Advanced visualization

πŸ“§ Support

For questions and support:

  • Open an issue on GitHub
  • Check existing issues for solutions
  • Review the troubleshooting section

Built with ❀️ using AI and Python

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages