Skip to content

toondb/toondb-python-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ToonDB Python Examples

Official Python examples for ToonDB - the high-performance embedded database for AI applications. This repository showcases integration patterns with popular agent frameworks and demonstrates ToonDB's unique features.

πŸ“‚ Repository Structure

toondb-python-examples/
β”œβ”€β”€ agent_memory/          # Production agent memory system with HNSW index
β”œβ”€β”€ azure_openai/          # Azure OpenAI integration examples
β”œβ”€β”€ complete_examples/     # Framework integrations (LangGraph, AutoGen, CrewAI)
β”œβ”€β”€ context_builder/       # Token-budget aware context assembly
β”œβ”€β”€ ecommerce/             # eCommerce product catalog RAG
β”œβ”€β”€ langgraph/             # LangGraph checkpointer and memory
β”œβ”€β”€ podcast/               # Podcast transcript search
β”œβ”€β”€ rag/                   # Complete RAG pipeline
β”œβ”€β”€ wizard_of_oz/          # Long-form text ingestion
└── zep/                   # Zep-compatible examples

πŸš€ Quick Start

Prerequisites

  • Python 3.10+ installed
  • ToonDB Python SDK: toondb-client>=0.3.3

Installation

pip install toondb-client>=0.3.3

πŸ“š Examples by Category

🧠 Agent Memory & State

1. Agent Memory (agent_memory/)

Production-ready agent memory system with vector search and HNSW index.

Features:

  • Long-term memory with semantic search
  • Session-based memory management
  • Time-weighted retrieval
  • Performance tracking and metrics
  • HNSW vector index for fast similarity search

Use Cases: Multi-turn conversations, customer support agents, research assistants

cd agent_memory
pip install -r requirements.txt
python main.py

2. LangGraph Integration (langgraph/)

Best for: Building stateful LangGraph agents with persistent memory.

Features:

  • Custom ToonDB checkpointer for graph state
  • Long-term memory store for user interactions
  • Time-weighted context retrieval
  • Seamless LangGraph integration
cd langgraph
pip install -r requirements.txt  
python agent_with_toondb.py

3. Context Query Builder (context_builder/)

Best for: Managing LLM context under strict token budgets.

Features:

  • Priority-based content truncation
  • Token budget management
  • Intelligent context assembly
  • System + user + history + retrieval

Demonstrated Scenarios:

  • Ample budget (4000 tokens)
  • Tight budget (500 tokens)
  • ToonDB integration with TOON format
cd context_builder
pip install -r requirements.txt
python runner.py

πŸ” RAG & Retrieval Examples

4. RAG Pipeline (rag/)

Complete production RAG system with document ingestion, chunking, and query pipeline.

Features:

  • Document ingestion and chunking
  • Azure OpenAI embeddings
  • Vector search with ToonDB
  • Generation with context
cd rag
pip install -r requirements.txt
python main.py

5. eCommerce RAG (ecommerce/)

Best for: Product catalogs, shopping assistants, recommendation systems.

Features:

  • Hybrid search (semantic + metadata filtering)
  • TOON format for compact results
  • Structured product data ingestion
  • 100% accuracy on test queries
cd ecommerce
pip install -r requirements.txt
python runner.py

6. Azure OpenAI ("California Politics") (azure_openai/)

Best for: Fact retrieval systems with Azure OpenAI.

Features:

  • Entity-focused retrieval (Kamala Harris, Gavin Newsom)
  • High-precision fact extraction
  • Azure OpenAI embeddings and chat
  • 100% accuracy on political facts
cd azure_openai
pip install -r requirements.txt
python runner.py

πŸ“– Document & Text Processing

7. Wizard of Oz (wizard_of_oz/)

Best for: Long-context narrative understanding, book ingestion.

Features:

  • Paragraph-based chunking
  • Semantic search over narrative text
  • Character and plot retrieval
  • 100% accuracy on story queries
cd wizard_of_oz
pip install -r requirements.txt
python runner.py

8. Podcast Search (podcast/)

Best for: Audio transcripts, meeting notes, multi-speaker dialogue.

Features:

  • Speaker attribution parsing
  • Timestamp preservation
  • Turn-based segmentation
  • 100% accuracy on speaker/topic queries
cd podcast
pip install -r requirements.txt
python runner.py

πŸ› οΈ Framework Integrations

9. Complete Examples (complete_examples/)

Multi-framework integrations showing ToonDB with various agent frameworks.

Included:

  • LangGraph agent with ToonDB memory
  • AutoGen multi-agent with ToonDB
  • Chat history management
  • Graph-based examples
cd complete_examples
pip install -r requirements.txt
# Run individual examples
python langgraph_agent_with_toondb.py

10. Zep Port (zep/)

Best for: Users migrating from Zep or needing entity-centric memory.

Features:

  • Entity extraction and storage
  • User profile management
  • Conversation thread tracking
  • Zep-compatible API patterns
cd zep
pip install -r requirements.txt
python toondb_simple.py

ToonDB Demo Notebooks

Interactive Jupyter notebooks for learning ToonDB features through hands-on examples.

πŸ“š Notebooks

RAG + SQL + Transactions

Learn how to build an AI support agent with:

  • SQL queries for order data
  • KV storage for user preferences
  • Vector RAG with policy retrieval
  • TOON encoding (40-67% token savings)
  • ACID transactions

Key Concepts: execute_sql(), KV storage, vector collections, ContextQuery, TOON format, transactions


Multi-Agent IPC

Learn how to build coordinated multi-process systems with:

  • IPC mode (Unix socket)
  • Shared state across processes
  • Namespace isolation
  • Hybrid retrieval (vector + keyword with RRF)
  • ACID state machines

Key Concepts: IPC mode, IpcClient, namespaces, hybrid search, state transitions


Spreadsheet + AI Analysis

Learn how to build data analysis agents with:

  • CSV ingestion to SQL
  • TOON vs JSON token comparison (with proof!)
  • Vector search over text fields
  • Token-budgeted context assembly
  • Churn prediction analysis

Key Concepts: CSV β†’ SQL, TOON encoding, token savings measurement, semantic search


πŸ”‘ Key ToonDB Features Demonstrated

  • TOON Format: Token-efficient output format (Database.to_toon())
  • Vector Search: Built-in HNSW index for semantic similarity
  • ACID Transactions: Group commits with Snapshot Isolation
  • Columnar Storage: Efficient projection-based reads
  • SQL Support: Optional SQL interface via IPC mode
  • Embedded Mode: Zero-config, file-based database

πŸ“– Documentation

βœ… Accuracy Testing

All examples include accuracy_test.py scripts with verified results:

Example Accuracy Test Cases
eCommerce 100% 4/4
Azure OpenAI 100% 4/4
Wizard of Oz 100% 3/3
Podcast 100% 4/4

🀝 Contributing

We welcome contributions! Please submit Pull Requests with:

  • New example implementations
  • Improvements to existing examples
  • Documentation enhancements
  • Bug fixes

πŸ“„ License

Apache License 2.0 - see the LICENSE file for details.

πŸ”— Related Repositories

Acknowledgements

Some of the agent memory examples (Wizard of Oz, Podcast, Zep ports) are referenced and adapted from the following projects:

About

ToonDB is a high-performance embedded, ACID-compliant database purpose-built for AI agents - python examples

Resources

License

Stars

Watchers

Forks