Examples
Overview

Examples

Implementation examples for common use cases.

Quick Examples

Minimal Setup

from remina import Memory
 
memory = Memory()
memory.add("I'm a Python developer", user_id="user_1")
results = memory.search("programming skills", user_id="user_1")
memory.close()

Custom Configuration

from remina import Memory
 
memory = Memory({
    "storage": {"provider": "postgres", "config": {...}},
    "vector_store": {"provider": "qdrant", "config": {...}},
    "embedder": {"provider": "gemini", "config": {...}},
    "llm": {"provider": "gemini", "config": {...}},
})

Async Usage

from remina import AsyncMemory
import asyncio
 
async def main():
    memory = AsyncMemory()
    await memory.add("I prefer async patterns", user_id="user_1")
    await memory.close()
 
asyncio.run(main())

Use Case Examples

AI Assistant with Memory

from remina import Memory
from openai import OpenAI
 
memory = Memory()
client = OpenAI()
 
def chat(user_id: str, message: str) -> str:
    # Retrieve relevant context
    memories = memory.search(message, user_id=user_id, limit=5)
    context = "\n".join([m["memory"] for m in memories["results"]])
    
    # Generate response with context
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "system", "content": f"User context:\n{context}"},
            {"role": "user", "content": message}
        ]
    )
    
    # Store conversation
    memory.add(
        messages=[
            {"role": "user", "content": message},
            {"role": "assistant", "content": response.choices[0].message.content}
        ],
        user_id=user_id
    )
    
    return response.choices[0].message.content

Customer Support System

from remina import Memory
 
memory = Memory({
    "storage": {"provider": "postgres", "config": {...}},
    "vector_store": {"provider": "pinecone", "config": {...}},
})
 
def handle_ticket(customer_id: str, issue: str):
    # Check for similar past issues
    past_issues = memory.search(
        query=issue,
        user_id=customer_id,
        limit=3,
        filters={"type": "support_ticket"}
    )
    
    # Store new issue
    memory.add(
        messages=issue,
        user_id=customer_id,
        metadata={"type": "support_ticket", "status": "open"}
    )
    
    return past_issues

Learning Platform

from remina import Memory
 
memory = Memory()
 
def record_session(student_id: str, topic: str, performance: float):
    memory.add(
        messages=f"Studied {topic} with {performance*100}% performance",
        user_id=student_id,
        metadata={
            "type": "learning_session",
            "topic": topic,
            "performance": performance
        }
    )
 
def get_weak_areas(student_id: str):
    return memory.search(
        query="low performance struggling",
        user_id=student_id,
        limit=10
    )

Running Examples

git clone https://github.com/bikidsx/remina
cd remina
pip install -e ".[all]"
python examples/gemini_production_stack.py