Skip to main content

Oracle

Oracle Database integrates with Memori through SQLAlchemy, so you can add AI agent memory to existing Oracle infrastructure.

Install

pip install memori oracledb

Quick Start

from memori import Memori
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

engine = create_engine(
    "oracle+oracledb://user:password@hostname:1521/service_name"
)
SessionLocal = sessionmaker(bind=engine)

mem = Memori(conn=SessionLocal)
mem.config.storage.build()

Connection Strings

FormatConnection String
oracledboracle+oracledb://user:pass@host:1521/service_name
cx_Oracleoracle+cx_oracle://user:pass@host:1521/service_name
TNS Nameoracle+oracledb://user:pass@tns_alias
Oracle Cloudoracle+oracledb://user:pass@host:1522/service?ssl_server_dn_match=yes

Complete Example

import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from memori import Memori
from openai import OpenAI

# Setup Oracle with connection pooling
engine = create_engine(
    "oracle+oracledb://memori_user:password@oracle-host:1521/ORCL",
    pool_pre_ping=True,
    pool_size=5,
    max_overflow=10,
    pool_recycle=300
)
SessionLocal = sessionmaker(bind=engine)

# Setup Memori with OpenAI
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
mem = Memori(conn=SessionLocal).llm.register(client)
mem.attribution(entity_id="user_123", process_id="my_agent")
mem.config.storage.build()

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Our quarterly review is on March 15."}]
)
print(response.choices[0].message.content)

mem.augmentation.wait()
facts = mem.recall("quarterly review date")
print(facts)

Oracle Cloud

For Oracle Autonomous Database, use the wallet-based connection:
import oracledb
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# Initialize Oracle client with wallet
oracledb.init_oracle_client(config_dir="/path/to/wallet")

engine = create_engine(
    "oracle+oracledb://ADMIN:password@db_alias"
    "?config_dir=/path/to/wallet"
    "&wallet_location=/path/to/wallet"
    "&wallet_password=wallet_password"
)
SessionLocal = sessionmaker(bind=engine)
Ensure the Oracle Instant Client is installed on your system for the oracledb driver to work properly.

Connection Pooling

Recommended settings for enterprise deployments:
engine = create_engine(
    "oracle+oracledb://user:password@host:1521/service",
    pool_pre_ping=True,       # Verify connection health
    pool_size=5,              # Base pool size
    max_overflow=10,          # Additional connections
    pool_recycle=300          # Recycle after 5 minutes
)

Build docs developers (and LLMs) love