Skip to content

study-flamingo/thoughtlab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

79 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ThoughtLab πŸ’­

  • v0.2.0-alpha

A web-based research application that helps you discover meaningful connections between sources, observations, hypotheses, and concepts using graph database technology.

Features

βœ… Node Management - Create and manage observations, sources, and hypotheses βœ… Relationship Tracking - Connect nodes with typed relationships (SUPPORTS, CONTRADICTS, RELATES_TO, etc.) βœ… Interactive Graph Visualization - Visualize your knowledge graph with Cytoscape.js (zoom, pan, click nodes) βœ… RESTful API - Complete API for programmatic access βœ… Node Details Panel - Click nodes to view details βœ… Real-time Updates - Activity feed ready for live updates (WebSocket integration coming soon) βœ… AI-Powered Analysis - LLM-powered graph operations via REST API, LangGraph agents, and MCP server βœ… Claude Desktop Integration - Use Claude to interact with your knowledge graph via MCP βœ… Intelligent Agents - LangGraph agents with automatic tool selection for complex reasoning βœ… Vector Search - Semantic similarity search using OpenAI embeddings

Quickstart

Prerequisites

  • Python 3.11+ (python3 --version)
  • Node.js 18+ (node --version)
  • Docker & Docker Compose (docker --version)

One-Command Setup

# Linux/Mac/WSL/Git Bash
./scripts/setup.sh

# Windows (PowerShell)
.\scripts\setup.ps1

This will:

  • βœ… Choose your development mode (Docker, Mixed, or Local)
  • βœ… Install Python dependencies (using uv)
  • βœ… Install Node.js dependencies
  • βœ… Create and configure .env files
  • βœ… Start Docker services (Neo4j, Redis)
  • βœ… Initialize Neo4j database

Start the App

./scripts/start.sh

This starts backend and frontend servers. Open http://localhost:5173 in your browser.

Other Commands

./scripts/stop.sh         # Stop all servers
./scripts/restart.sh      # Restart all servers
./scripts/start-docker.sh # Start fully containerized

For detailed script documentation, see SCRIPTS.md or docs/SCRIPTS.md.

Manual Setup

If you prefer to set things up manually:

1. Start Database Services

docker-compose up -d
docker-compose ps  # Verify services are healthy

2. Set Up Backend

cd backend
uv venv && source .venv/bin/activate  # Windows: .venv\Scripts\activate
uv pip install -r requirements.txt
cp .env.example .env
# Edit .env and set SECRET_KEY (or setup.sh does this automatically)
uvicorn app.main:app --reload

3. Set Up Frontend

cd frontend
npm install
cp .env.example .env
npm run dev

4. Initialize Neo4j (First Time Only)

docker exec research-graph-neo4j cypher-shell -u neo4j -p research_graph_password < docker/neo4j/init.cypher

Usage

Creating Nodes

Via Web Interface

  1. Open http://localhost:5173
  2. Click "+ Add Node" button
  3. Select node type (Observation, Source, Hypothesis, Entity)
  4. Fill in the form and click "Create"

Via API

# Create an observation
curl -X POST "http://localhost:8000/api/v1/nodes/observations" \
  -H "Content-Type: application/json" \
  -d '{"text": "I observed that X leads to Y", "confidence": 0.8}'

# Create a source
curl -X POST "http://localhost:8000/api/v1/nodes/sources" \
  -H "Content-Type: application/json" \
  -d '{"title": "Research Paper", "url": "https://example.com", "source_type": "paper"}'

Creating Relationships

curl -X POST "http://localhost:8000/api/v1/nodes/relationships" \
  -H "Content-Type: application/json" \
  -d '{
    "from_id": "node-id-1",
    "to_id": "node-id-2",
    "relationship_type": "SUPPORTS",
    "confidence": 0.9
  }'

Relationship types: SUPPORTS, CONTRADICTS, RELATES_TO, OBSERVED_IN, DISCUSSES, EXTRACTED_FROM, DERIVED_FROM

Graph Visualization

  • Zoom: Mouse wheel or pinch gesture
  • Pan: Click and drag background
  • Select Node: Click to view details
  • Node Colors:
    • πŸ”΅ Blue (circle) = Observation
    • 🟒 Green (diamond) = Hypothesis
    • 🟑 Yellow (rectangle) = Source
    • 🟣 Purple (hexagon) = Concept
    • πŸ”΄ Red (rounded rectangle) = Entity

API Documentation

Project Structure

thoughtlab/
β”œβ”€β”€ setup.sh              # One-command setup
β”œβ”€β”€ start.sh              # Start all servers
β”œβ”€β”€ stop.sh               # Stop all servers
β”œβ”€β”€ restart.sh            # Restart servers
β”œβ”€β”€ backend/              # Python FastAPI backend
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/routes/   # API endpoints
β”‚   β”‚   β”œβ”€β”€ agents/       # LangGraph agents
β”‚   β”‚   β”œβ”€β”€ ai/           # AI workflow (embeddings, similarity)
β”‚   β”‚   β”œβ”€β”€ core/         # Configuration
β”‚   β”‚   β”œβ”€β”€ db/           # Database connections
β”‚   β”‚   β”œβ”€β”€ mcp/          # MCP server (mounted at /mcp)
β”‚   β”‚   β”œβ”€β”€ models/       # Pydantic models
β”‚   β”‚   β”œβ”€β”€ services/     # Business logic
β”‚   β”‚   β”‚   └── tools/    # Modular tool service
β”‚   β”‚   └── tools/        # Shared tool definitions
β”‚   └── tests/            # Backend tests
β”œβ”€β”€ frontend/             # React TypeScript frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/   # React components
β”‚   β”‚   β”œβ”€β”€ services/     # API client
β”‚   β”‚   └── types/        # TypeScript types
β”‚   └── package.json
β”œβ”€β”€ docker-compose.yml    # Database services
β”œβ”€β”€ docs/                 # Documentation
└── scripts/              # Utility scripts
    β”œβ”€β”€ setup.ps1         # Windows PowerShell setup
    └── install-hooks.sh  # Install git hooks

Testing

Backend

cd backend && source .venv/bin/activate
pytest                              # Run tests
pytest --cov=app --cov-report=html  # With coverage

Frontend

cd frontend
npm test                 # Run tests
npm run test:coverage    # With coverage

See TESTING.md for details.

Configuration

Backend (backend/.env)

NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=research_graph_password
DATABASE_URL=sqlite:///./research_graph.db
REDIS_URL=redis://localhost:6379
SECRET_KEY=your-secret-key-here

# AI Configuration (required for AI tools)
THOUGHTLAB_OPENAI_API_KEY=sk-...
THOUGHTLAB_LLM_MODEL=gpt-4o-mini
THOUGHTLAB_EMBEDDING_MODEL=text-embedding-3-small

# MCP Server (optional)
THOUGHTLAB_MCP_ADMIN_MODE=false  # Enable dangerous tools in MCP

Frontend (frontend/.env)

VITE_API_URL=http://localhost:8000/api/v1

Security

This project includes security scanning:

  • GitHub Action: Scans for secrets on every push/PR using Gitleaks
  • Pre-commit hook: Local secret detection (install with ./scripts/install-hooks.sh)
  • Dependency audits: npm and pip dependencies are scanned

See SECURITY.md for details.

Troubleshooting

Backend won't start

# Check if port 8000 is in use
lsof -i :8000  # or: netstat -an | grep 8000

# Make sure venv is activated
source backend/.venv/bin/activate

Frontend connection errors

Docker issues

# Check service logs
docker-compose logs neo4j

# Reset (WARNING: deletes data)
docker-compose down -v && docker-compose up -d

Neo4j not ready

Neo4j takes ~30 seconds to start. Wait and retry, or check:

docker-compose ps  # Should show "healthy"

Documentation

Core Documentation

Detailed References

Current Status

βœ… Implemented

  • Backend API with CRUD operations
  • Frontend UI with node creation
  • Graph database (Neo4j) integration
  • Relationship management
  • Interactive graph visualization
  • Activity feed with processing status
  • AI-powered relationship discovery (LangChain + LangGraph)
  • Vector embeddings and similarity search
  • Automatic connection suggestions based on semantic similarity
  • Comprehensive test suite
  • Security scanning (Gitleaks)
  • LLM-powered graph operations (10 AI tools: find related, summarize, reclassify, merge nodes, etc.)
  • MCP server at /mcp endpoint for Claude Desktop integration
  • LangGraph agents with intelligent tool selection
  • Unified tool architecture - shared definitions for REST API, LangGraph, and MCP

🚧 Coming Soon

  • Real-time WebSocket updates
  • Advanced search and filtering
  • User authentication
  • Graph export/import
  • Chrome extension for web capture

License

MIT License - See LICENSE for details.

Contributing

  1. Install git hooks: ./scripts/install-hooks.sh
  2. Create a feature branch
  3. Make changes and run tests
  4. Submit a pull request

See SECURITY.md for security guidelines.

About

Connect your Knowledge

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors