Skip to main content

Overview

The ID Manager automatically generates sequential IDs for database records with conflict resolution.

Features

  • Sequential IDs - Automatic integer ID generation
  • Conflict Resolution - Handles ID conflicts automatically
  • Database Sync - Stays in sync with database
  • Error Recovery - Robust retry logic

Automatic Usage

The ID Manager is used automatically by LangChat:
from langchat import LangChat
from langchat.llm import OpenAI
from langchat.vector_db import Pinecone
from langchat.database import Supabase

llm = OpenAI(api_key="sk-...", model="gpt-4o-mini")
vector_db = Pinecone(api_key="...", index_name="...")
db = Supabase(url="https://...", key="...")

ai = LangChat(llm=llm, vector_db=vector_db, db=db)

# ID Manager is automatically used when saving chat history
You don’t need to use ID Manager directly - it works automatically behind the scenes.

How It Works

  1. Check Database - Finds highest existing ID
  2. Generate Next ID - Creates next sequential ID
  3. Insert with Retry - Inserts with conflict resolution
  4. Handle Conflicts - Automatically retries on conflicts

Advanced Usage

Access ID Manager directly:
from langchat.adapters.database.id_manager import IDManager

# Initialize
id_manager = IDManager(supabase_client)

# Generate ID for table
next_id = id_manager.get_next_id("chat_history")

Best Practices

The ID Manager handles everything automatically. No manual configuration needed.

Next Steps


Built with ❤️ by NeuroBrain