mouimet-infinisoft / ibrain-cli

0 stars 0 forks source link

Persistent Memory #1

Closed mouimet-infinisoft closed 4 months ago

mouimet-infinisoft commented 4 months ago

1. Storing Discussions as Persistent Memory

Objective: To store and retrieve past interactions with the AI, allowing the AI to refer back to previous discussions for context.

Approach:

Implementation Steps:

  1. Set Up the Database: Create a table in PostgreSQL to store chat interactions.

    CREATE TABLE chat_history (
       id SERIAL PRIMARY KEY,
       user_id VARCHAR(50),
       message TEXT,
       response TEXT,
       timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
    );
  2. Store Interactions: Modify your chat application to store each interaction in the database.

    // Example using Supabase client in TypeScript
    const { data, error } = await supabase
       .from('chat_history')
       .insert([
           { user_id: 'user123', message: userMessage, response: aiResponse }
       ]);
  3. Retrieve Past Interactions: Implement a function to fetch relevant past interactions.

    const { data, error } = await supabase
       .from('chat_history')
       .select('*')
       .eq('user_id', 'user123')
       .order('timestamp', { ascending: false })
       .limit(10);