Skip to main content
Database integration provides persistent and in-memory storage for agent knowledge and sessions.

Quick Start

1

In-Memory Vector Store

use praisonai::{Agent, InMemoryVectorStore, VectorRecord};

// Create vector store for semantic search
let mut store = InMemoryVectorStore::new();

// Add knowledge
let record = VectorRecord::new("doc-1", "AI agents are autonomous systems")
    .with_embedding(vec![0.1, 0.2, 0.3]);
store.add(record).await?;

// Create agent with knowledge
let agent = Agent::new()
    .name("Researcher")
    .knowledge(store)
    .build()?;

agent.start("What are AI agents?").await?;
2

File-Based Sessions

use praisonai::{Agent, FileSessionStore};

// Persist conversations to disk
let store = FileSessionStore::new();

let agent = Agent::new()
    .name("Assistant")
    .session_store(store)
    .build()?;

// Conversations persist across restarts
agent.start("Remember this context").await?;

User Interaction Flow


InMemoryVectorStore

Fast, in-memory vector storage for development and small knowledge bases.
pub struct InMemoryVectorStore {
    records: Vec<VectorRecord>,
}

Methods

MethodSignatureDescription
new()fn new() -> SelfCreate empty store
add(record)async fn add(&mut self, VectorRecord) -> Result<String>Add a record
search(embedding, limit)async fn search(&self, &[f32], usize) -> Result<Vec<SearchResultItem>>Search by embedding
get(id)async fn get(&self, &str) -> Result<Option<VectorRecord>>Get by ID
delete(id)async fn delete(&mut self, &str) -> Result<bool>Delete by ID

Example

use praisonai::{InMemoryVectorStore, VectorRecord, VectorStoreProtocol};

let mut store = InMemoryVectorStore::new();

// Add records with embeddings
let record = VectorRecord::new("id-1", "Document content")
    .with_embedding(vec![0.1, 0.2, 0.3, 0.4]);

store.add(record).await?;

// Search for similar content
let results = store.search(&[0.1, 0.2, 0.3, 0.4], 5).await?;
for item in results {
    println!("Found: {} (score: {})", item.text, item.score);
}

FileSessionStore

Persistent file-based storage for session data.
pub struct FileSessionStore {
    session_dir: PathBuf,
    max_messages: usize,
}

Configuration Options

OptionTypeDefaultDescription
session_dirPathBuf~/.praisonai/sessions/Storage directory
max_messagesusize100Max messages per session

Methods

MethodSignatureDescription
new()fn new() -> SelfDefault directory
with_dir(dir)fn with_dir(impl Into<PathBuf>) -> SelfCustom directory
max_messages(n)fn max_messages(self, usize) -> SelfSet limit

Storage Comparison

StorePersistenceUse CasePerformance
InMemoryVectorStoreMemory onlyDevelopment, testing⚡ Fastest
FileSessionStoreDiskProduction sessions💾 Durable

Best Practices

Fast iteration without database setup. Switch to persistent store for production.
Use FileSessionStore::new().max_messages(100) to prevent unbounded growth.
Vector stores search by embedding similarity - structure your documents for semantic retrieval.