Skip to content
/ memos Public

A modern, AI-powered chat history storage and management system with semantic search capabilities. Store, organize, and intelligently retrieve conversational data across multiple sessions and users.

Notifications You must be signed in to change notification settings

memosapp/memos

Repository files navigation

🧠 Memos - Intelligent Chat History Management

A modern, AI-powered chat history storage and management system with semantic search capabilities. Store, organize, and intelligently retrieve conversational data across multiple sessions and users.

πŸš€ Project Overview

Memos is a full-stack application designed to revolutionize how we store and retrieve conversational data. By combining traditional keyword search with AI-powered semantic similarity, it provides an intelligent system for managing chat histories, conversations, and memory-based interactions.

✨ Key Features

  • πŸ” Hybrid Search: Combines keyword matching (30%) with semantic similarity (70%) for intelligent retrieval
  • πŸ€– AI-Powered: Leverages Google Gemini AI for generating high-quality text embeddings
  • πŸ‘₯ Multi-User Support: Handle multiple users and conversation sessions
  • πŸ“Š Vector Database: Supabase PostgreSQL with pgvector for efficient semantic search
  • πŸ”— MCP Integration: Model Context Protocol server for AI tool integration
  • ⚑ Real-time: Modern React frontend with real-time updates
  • 🐳 Docker Ready: Full containerized development environment with hot reload
  • πŸ”„ Hot Reload: All services support hot reload for rapid development

πŸ› οΈ Tech Stack

Backend

  • Runtime: Node.js 18+
  • Framework: Express.js with TypeScript
  • Database: Supabase PostgreSQL with pgvector extension
  • AI Service: Google Gemini AI (gemini-embedding-001)
  • Vector Dimensions: 1536-dimensional embeddings

Frontend

  • Framework: Next.js 15+ with React 19
  • UI Library: Radix UI + Tailwind CSS
  • State Management: Redux Toolkit
  • Styling: Tailwind CSS with custom animations
  • Icons: Lucide React + React Icons

MCP (Model Context Protocol)

  • SDK: @modelcontextprotocol/sdk
  • Runtime: TypeScript with tsx
  • Validation: Zod for schema validation

Development Tools

  • Package Manager: pnpm
  • Build Tool: TypeScript compiler
  • Development: Hot-reload with ts-node-dev
  • Containerization: Docker & Docker Compose

πŸ“¦ Installation and Setup

Prerequisites

  • Node.js 18 or higher
  • pnpm (recommended) or npm
  • Docker and Docker Compose
  • Google Gemini AI API key

Quick Start

🐳 Docker Setup (Recommended)

  1. Clone the repository

    git clone <repository-url>
    cd memos
  2. Configure environment variables

    # Create backend environment file
    echo "GEMINI_API_KEY=your_gemini_api_key_here" > apps/backend/.env
  3. Start all services with Docker

    # Start all services (database, backend, frontend, MCP server)
    ./start-dev.sh
    
    # Or manually
    docker-compose up -d
  4. Access the application

  5. Verify services are running

    ./verify-ports.sh
  6. Stop services

    ./stop-dev.sh
    # Or manually
    docker-compose down

πŸ”§ Manual Setup (Alternative)

  1. Clone the repository

    git clone <repository-url>
    cd memos
  2. Install dependencies

    pnpm install
  3. Set up the database

    # Start PostgreSQL with pgvector
    docker-compose up -d postgres
    
    # Or use the setup script
    ./setup-db.sh
  4. Configure environment variables

    # Create backend environment file
    cp apps/backend/.env.example apps/backend/.env
    
    # Edit the file with your configuration
    nano apps/backend/.env

    Required environment variables:

    PORT=3000
    DB_HOST=localhost
    DB_PORT=5432
    DB_USER=memos_user
    DB_PASSWORD=memos_password
    DB_NAME=memos
    GEMINI_API_KEY=your_gemini_api_key_here
  5. Start the development servers

    # Terminal 1: Start backend
    cd apps/backend
    pnpm dev
    
    # Terminal 2: Start frontend
    cd apps/frontend
    pnpm dev
    
    # Terminal 3: Start MCP server (optional)
    cd apps/mcp
    pnpm dev
  6. Access the application

πŸ“ Folder Structure

memos/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ backend/                 # Node.js REST API
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ controllers/     # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ routes/          # API endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ services/        # External services (AI)
β”‚   β”‚   β”‚   β”œβ”€β”€ config/          # Database & AI configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ types/           # TypeScript definitions
β”‚   β”‚   β”‚   β”œβ”€β”€ utils/           # Utility functions
β”‚   β”‚   β”‚   β”œβ”€β”€ app.ts           # Express app setup
β”‚   β”‚   β”‚   └── server.ts        # Entry point
β”‚   β”‚   β”œβ”€β”€ database.sql         # Database schema
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   β”œβ”€β”€ frontend/                # Next.js React application
β”‚   β”‚   β”œβ”€β”€ app/                 # Next.js 15 app directory
β”‚   β”‚   β”‚   β”œβ”€β”€ memories/        # Memory management pages
β”‚   β”‚   β”‚   β”œβ”€β”€ settings/        # Settings page
β”‚   β”‚   β”‚   └── layout.tsx       # Root layout
β”‚   β”‚   β”œβ”€β”€ components/          # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/              # Radix UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ shared/          # Shared components
β”‚   β”‚   β”‚   └── dashboard/       # Dashboard components
β”‚   β”‚   β”œβ”€β”€ hooks/               # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ store/               # Redux store
β”‚   β”‚   β”œβ”€β”€ lib/                 # Utility libraries
β”‚   β”‚   └── styles/              # Global styles
β”‚   β”‚
β”‚   └── mcp/                     # Model Context Protocol server
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   └── index.ts         # MCP server entry point
β”‚       └── package.json
β”‚
β”œβ”€β”€ packages/
β”‚   └── shared/                  # Shared utilities & types
β”‚
β”œβ”€β”€ docker-compose.yml           # All services setup
β”œβ”€β”€ setup-db.sh                 # Database setup script
β”œβ”€β”€ start-dev.sh                # Start development environment
β”œβ”€β”€ stop-dev.sh                 # Stop development environment
β”œβ”€β”€ verify-ports.sh             # Port verification script
β”œβ”€β”€ pnpm-workspace.yaml         # Workspace configuration
└── README.md                   # This file

πŸƒβ€β™‚οΈ How to Run and Test

Development Mode

🐳 Docker Development (Recommended)

# Start all services with hot reload
./start-dev.sh

# View logs
docker-compose logs -f

# Stop services
./stop-dev.sh

# Rebuild specific service
docker-compose build backend
docker-compose up -d backend

πŸ”§ Manual Development

# Start all services in development mode
pnpm dev

# Or start individual services
cd apps/backend && pnpm dev    # Backend on port 3000
cd apps/frontend && pnpm dev   # Frontend on port 3000
cd apps/mcp && pnpm dev        # MCP server

Production Build

# Build all applications
pnpm build

# Or build individual apps
cd apps/backend && pnpm build
cd apps/frontend && pnpm build
cd apps/mcp && pnpm build

Testing the API

# Health check
curl http://localhost:3001/health

# Create a new memo
curl -X POST http://localhost:3001/memo \
  -H "Content-Type: application/json" \
  -d '{
    "sessionId": "session_123",
    "userId": "user_456",
    "content": "This is a test memo about machine learning",
    "authorRole": "user",
    "tags": ["test", "ml", "ai"]
  }'

# Search memos
curl -X POST http://localhost:3001/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "machine learning",
    "limit": 10,
    "sessionId": "session_123"
  }'

# Get all memos
curl http://localhost:3001/memos

# Get specific memo
curl http://localhost:3001/memo/1

Database Management

# Start database
docker-compose up -d postgres

# Stop database
docker-compose down

# View database logs
docker-compose logs -f postgres

# Access database directly
docker-compose exec postgres psql -U memos_user -d memos

πŸ“– API Reference

Base URL

http://localhost:3001

Authentication

Currently, the API does not require authentication. This may change in future versions.

Endpoints

Health Check

GET /health

Response:

{
  "status": "ok",
  "timestamp": "2024-01-01T00:00:00.000Z"
}

Create Memo

POST /memo

Request Body:

{
  "sessionId": "string",
  "userId": "string",
  "content": "string",
  "authorRole": "user" | "agent" | "system",
  "summary": "string (optional)",
  "importance": 1.0,
  "tags": ["string"]
}

Response:

{
  "id": 1,
  "sessionId": "session_123",
  "userId": "user_456",
  "content": "This is a test memo",
  "authorRole": "user",
  "importance": 1.0,
  "accessCount": 0,
  "tags": ["test"],
  "createdAt": "2024-01-01T00:00:00.000Z",
  "updatedAt": "2024-01-01T00:00:00.000Z"
}

Get Memos

GET /memos?sessionId=session_123&userId=user_456&limit=10&offset=0

Query Parameters:

  • sessionId (optional): Filter by session
  • userId (optional): Filter by user
  • limit (optional): Number of results (default: 50)
  • offset (optional): Pagination offset (default: 0)

Get Memo by ID

GET /memo/:id

Response: Same as Create Memo response

Update Memo

PATCH /memo/:id

Request Body: Same as Create Memo (all fields optional)

Delete Memo

DELETE /memo/:id

Response:

{
  "message": "Memo deleted successfully"
}

Search Memos

POST /search

Request Body:

{
  "query": "string",
  "limit": 10,
  "sessionId": "string (optional)",
  "userId": "string (optional)"
}

Response:

{
  "results": [
    {
      "id": 1,
      "content": "...",
      "similarity": 0.95,
      "relevanceScore": 0.87
    }
  ],
  "total": 1,
  "processingTime": "0.123s"
}

🀝 Contributing

We welcome contributions to the Memos project! Please follow these guidelines:

Development Guidelines

  1. Code Style

    • Use TypeScript with strict type checking
    • Follow ESLint and Prettier configurations
    • Write descriptive commit messages using conventional commits
    • Maintain consistent code formatting
  2. Before Contributing

    • Check existing issues and pull requests
    • Fork the repository and create a feature branch
    • Ensure all tests pass and linting is clean
    • Update documentation for any API changes
  3. Pull Request Process

    • Create descriptive pull request titles
    • Include detailed description of changes
    • Reference related issues
    • Ensure CI/CD pipelines pass
    • Request review from maintainers

Setting Up Development Environment

# Fork and clone the repository
git clone https://github.com/yourusername/memos.git
cd memos

# Install dependencies
pnpm install

# Create a new feature branch
git checkout -b feature/your-feature-name

# Make your changes and commit
git add .
git commit -m "feat: add new feature"

# Push to your fork
git push origin feature/your-feature-name

Code Quality Standards

  • Testing: Write unit tests for new features
  • Documentation: Update README and inline documentation
  • Error Handling: Implement proper error handling and logging
  • Performance: Consider performance implications of changes
  • Security: Follow security best practices

Reporting Issues

When reporting bugs or requesting features:

  1. Check existing issues first
  2. Use the appropriate issue template
  3. Provide detailed reproduction steps
  4. Include system information and logs
  5. Tag issues appropriately

Architecture Decisions

  • Follow the established layered architecture
  • Keep components focused and single-purpose
  • Maintain clear separation between frontend and backend
  • Use TypeScript interfaces for data contracts
  • Follow REST API conventions

πŸ“„ License

This project is licensed under the ISC License. See the LICENSE file for details.

🌐 Service URLs

πŸ” Port Verification

Run the verification script to check all services:

./verify-ports.sh

πŸ™ Acknowledgments

  • Google Gemini AI for embedding generation
  • PostgreSQL and pgvector for vector database capabilities
  • The React and Next.js communities for excellent tooling
  • All contributors and maintainers

For more detailed information, see the PROJECT_OVERVIEW.md file.

Happy coding! πŸš€

About

A modern, AI-powered chat history storage and management system with semantic search capabilities. Store, organize, and intelligently retrieve conversational data across multiple sessions and users.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published