Memory Core
A dual-output AI pipeline that enables natural conversation while seamlessly storing and retrieving data from databases.
The Core Idea
Traditional chatbots either just talk or just query databases. Our Memory Core does both simultaneously through a 2-prompt classification pipeline that routes each message to the right handler.
Key Innovation: The AI classifies each message and decides whether to respond conversationally (LOOP) or perform a data operation (BREAK) - all while maintaining natural dialogue.
Dual Output System
Every user message goes through a classifier that determines one of two actions:
LOOP
Continue conversation naturally
- Greetings and small talk
- General questions
- Follow-up clarifications
- Thank you messages
BREAK
Perform database operation
- Book appointments
- Save user preferences
- Query stored data
- Update records
Pipeline Architecture
The 2-prompt pipeline processes every message through classification, then routes to the appropriate handler.
┌─────────────────────────────────────────────────────────────────────────────────┐
│ MEMORY SYSTEM PIPELINE │
└─────────────────────────────────────────────────────────────────────────────────┘
User Message: "Book me a haircut for tomorrow at 3pm"
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ PROMPT 1: CLASSIFIER │
│ │
│ System: Analyze the user's intent. Determine if this requires: │
│ - LOOP: Normal conversation, continue chatting │
│ - BREAK: Data operation needed (create, read, update, delete) │
│ │
│ Output: { "action": "BREAK", "operation": "INSERT", "table": "bookings" } │
└─────────────────────────────────────────────────────────────────────────────┘
│
┌───────────────┴───────────────┐
│ │
▼ ▼
┌───────────────────────────┐ ┌───────────────────────────────────────────┐
│ LOOP │ │ BREAK │
│ │ │ │
│ Return AI response │ │ ┌─────────────────────────────────────┐ │
│ directly to user │ │ │ PROMPT 2: SQL GENERATOR │ │
│ │ │ │ │ │
│ "Hello! How can I │ │ │ Generate parameterized SQL: │ │
│ help you today?" │ │ │ │ │
│ │ │ │ INSERT INTO bookings │ │
└───────────────────────────┘ │ │ (customer, service, datetime) │ │
│ │ VALUES (?, ?, ?) │ │
│ └─────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────┐ │
│ │ EXECUTE & RESPOND │ │
│ │ │ │
│ │ 1. Execute SQL safely │ │
│ │ 2. Format result for user │ │
│ │ │ │
│ │ "I've booked your haircut for │ │
│ │ tomorrow at 3pm!" │ │
│ └─────────────────────────────────────┘ │
└───────────────────────────────────────────┘
Three-Tier Memory
The system maintains three distinct layers of memory, each serving a different purpose.
Short-Term Memory
Current conversation context
Long-Term Memory
User data and preferences
Knowledge Base
Documents & semantic search
Database Operations
When the classifier outputs BREAK, the system generates and executes safe, parameterized SQL.
Supported Operations
| Operation | Trigger Examples | Generated SQL |
|---|---|---|
INSERT |
"Book me...", "Save my...", "Add a..." | INSERT INTO table (...) VALUES (?) |
SELECT |
"Show my...", "What are...", "List all..." | SELECT * FROM table WHERE ... |
UPDATE |
"Change my...", "Update the...", "Reschedule..." | UPDATE table SET ... WHERE ... |
DELETE |
"Cancel my...", "Remove the...", "Delete..." | DELETE FROM table WHERE ... |
Example Flow
// User says:
"I want to book a consultation for next Monday at 2pm"
// Classifier output (Prompt 1):
{
"action": "BREAK",
"operation": "INSERT",
"table": "appointments",
"data": {
"service": "consultation",
"date": "2024-01-15",
"time": "14:00"
}
}
// Generated SQL (Prompt 2):
INSERT INTO appointments (session_id, service, appointment_date, appointment_time)
VALUES (?, ?, ?, ?)
// AI Response:
"I've scheduled your consultation for Monday, January 15th at 2:00 PM."
Semantic Knowledge Search
When the AI needs information beyond structured data, it automatically searches your uploaded documents using meaning-based matching.
Understand
Parse user intent
Search
Match by meaning
Retrieve
Get relevant context
Respond
Answer naturally
Knowledge search is triggered automatically when the classifier detects a question that can't be answered from structured data.
// User asks about business hours (not in database)
"What time do you open on Saturdays?"
// System searches knowledge base, finds:
{
"chunk": "Weekend hours: Saturday 9am-5pm, Sunday closed",
"similarity": 0.92
}
// AI Response with retrieved context:
"We're open on Saturdays from 9 AM to 5 PM!"
Use Cases
Booking System
Natural language appointment scheduling
"Book me a haircut tomorrow at 3pm"
→ INSERT INTO bookings
E-commerce
Order tracking and preferences
"Where's my order #1234?"
→ SELECT FROM orders
CRM
Customer data management
"Update John's email to new@email.com"
→ UPDATE customers
Support Bot
FAQ + ticket creation
"How do I reset password?" → Knowledge
"Create a ticket" → INSERT
Complete Message Flow
Receive Message
User sends a message through chat interface. Message is sanitized and session context is loaded.
Classify Intent
First AI prompt analyzes the message and outputs LOOP (conversation) or BREAK (data operation).
Route to Handler
LOOP returns AI response directly. BREAK triggers SQL generation and database interaction.
Check Knowledge Base
If needed, semantic search finds relevant knowledge to augment the response.
Generate Response
AI crafts a natural language response incorporating any data or knowledge retrieved.
Store & Return
Message is saved to conversation history and response is returned to user.