Skip to content

santhosh-005/Smart_Memory

Repository files navigation

🧠 SmartMemory - Intelligent Memory System

An intelligent data processing system that creates a knowledge graph of data relationships using vector embeddings and AI analysis.

🎯 What It Does (example: email)

SmartMemory automatically processes emails to:

  • Generate vector embeddings using Google Gemini AI
  • Store emails in Supabase PostgreSQL with pgvector
  • Find semantically similar emails using vector similarity search
  • Analyze relationships between emails using LLM
  • Build knowledge graphs in Neo4j showing email connections

πŸ—οΈ System Architecture

πŸ“§ Email Input
    ↓
πŸ€– Gemini Embedding (1536-dim vectors)
    ↓
πŸ—„οΈ  Supabase Storage (PostgreSQL + pgvector)
    ↓
πŸ” Vector Similarity Search
    ↓
🧠 LLM Relationship Analysis
    ↓
πŸ•ΈοΈ  Neo4j Knowledge Graph

πŸ› οΈ Tech Stack

Component Technology Purpose
AI/ML Google Gemini API Vector embeddings & relationship analysis
Database Supabase PostgreSQL Email storage with pgvector extension
Graph DB Neo4j AuraDB Knowledge graph for email relationships
Backend Python 3.11+ Main processing logic
Environment python-dotenv Configuration management

πŸ“ Project Structure

SmartMemory/
β”œβ”€β”€ .env                           # Environment variables (API keys, DB credentials)
β”œβ”€β”€ .gitignore                     # Git ignore rules
β”œβ”€β”€ config.py                      # Configuration management
β”œβ”€β”€ email_processor.py             # Main email processing pipeline
β”œβ”€β”€ gemini_service.py              # Gemini AI embedding & analysis
β”œβ”€β”€ supabase_client.py             # Supabase database operations
β”œβ”€β”€ neo4j_client.py                # Neo4j graph database operations
β”œβ”€β”€ main.py                        # Application entry point
β”œβ”€β”€ test_connections.py            # Connection testing utility
β”œβ”€β”€ setup_supabase_function.sql    # SQL function for vector similarity
└── README.md                      # This file

πŸš€ Quick Start

1. Prerequisites

  • Python 3.11+
  • Google Gemini API key
  • Supabase account with PostgreSQL + pgvector
  • Neo4j AuraDB instance

2. Installation

git clone https://github.com/santhosh-005/Smart_Memory.git
cd Smart_Memory

# Create virtual environment
python -m venv .venv
.venv\Scripts\activate  # Windows
# source .venv/bin/activate  # macOS/Linux

# Install dependencies
pip install google-generativeai supabase neo4j python-dotenv

3. Configuration

Create .env file with your credentials:

# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key

# Gemini API Configuration  
GEMINI_API_KEY=your_gemini_api_key

# Neo4j Configuration
NEO4J_URI=your_neo4j_uri
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your_neo4j_password

4. Database Setup

Supabase Setup:

  1. Create emails table:
CREATE TABLE IF NOT EXISTS emails (
  id BIGSERIAL PRIMARY KEY,
  title TEXT NOT NULL,
  body TEXT NOT NULL,
  created_at TIMESTAMPTZ DEFAULT now(),
  embedding vector(1536)
);
  1. Run the SQL from setup_supabase_function.sql in your Supabase SQL Editor

Neo4j Setup:

  • No additional setup required - the system creates nodes and relationships automatically

5. Run the System

# Test connections
python test_connections.py

# Process sample emails
python main.py

πŸ”„ System Workflow

Email Processing Pipeline:

  1. πŸ“₯ Email Input: Title and body text
  2. 🎯 Content Preparation: Combine title + body for comprehensive context
  3. πŸ€– Generate Embedding: Use Gemini with RETRIEVAL_DOCUMENT task type
  4. πŸ’Ύ Store in Supabase: Save email with 1536-dimension vector
  5. πŸ“Š Create Neo4j Node: Add email node to knowledge graph
  6. πŸ” Find Similar Emails: Use pgvector similarity search via RPC function
  7. 🧠 LLM Analysis: Analyze relationships using Gemini Pro
  8. πŸ”— Update Graph: Create relationship edges in Neo4j

Relationship Types Detected:

  • REPLY_TO - Direct email replies
  • FOLLOW_UP_ON - Follow-up discussions
  • REFERENCES_SAME_TOPIC - Related topic discussions
  • RELATED_TO - General relationships

πŸ“Š Example Usage

from email_processor import process_email

# Process an email
process_email(
    title="Project Update - Q4 Status", 
    body="Hi team, here's the latest update on our Q4 project..."
)

Output:

--- Processing new email: 'Project Update - Q4 Status' ---
Storing email in Supabase...
Stored successfully. New email ID: 123
Created initial node in Neo4j for email 123
Searching for similar emails...
Found 2 similar emails.
Querying LLM for relationship analysis...
LLM Response: {'relationship_found': True, 'target_email_id': 45, 'relationship_type': 'FOLLOW_UP_ON'}
Relationship found! Creating edge in Neo4j: (123)-[FOLLOW_UP_ON]->(45)
Graph updated.

πŸ”§ Configuration Options

Key settings in config.py:

EMBEDDING_DIMENSIONS = 1536      # Gemini embedding size
SIMILARITY_THRESHOLD = 0.7       # Minimum similarity for relationships  
MATCH_COUNT = 5                  # Max similar emails to analyze

πŸ§ͺ Testing

# Test all connections
python test_connections.py

# Process sample emails
python main.py

πŸ“ˆ Performance Considerations

  • Embedding Generation: ~1-2 seconds per email
  • Vector Search: Milliseconds with pgvector indexing
  • LLM Analysis: ~2-3 seconds for relationship detection
  • Graph Updates: Near-instantaneous

🚨 Common Issues

Gemini API Quota Exceeded

Supabase Connection Issues

  • Verify: URL and API key in .env
  • Check: pgvector extension is enabled

Neo4j Connection Issues

  • Verify: URI and credentials in .env
  • Check: AuraDB instance is running

πŸ›£οΈ Roadmap

  • Real-time Processing: WebSocket integration for live email processing
  • Advanced Relationships: Thread detection and conversation mapping
  • Search Interface: Query interface for finding related emails
  • Analytics Dashboard: Visualization of email networks
  • Batch Processing: Bulk email import functionality

πŸ“ License

This project is licensed under the MIT License.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“ž Support

For issues and questions:

  • Create an issue on GitHub
  • Check the troubleshooting section above
  • Review API documentation for Gemini, Supabase, and Neo4j

Built with ❀️ for intelligent email management

About

LLM Meomry Solve: Funtionality Clone of SuperMemory (Intial Version)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors