# Adapters

Database adapters provide persistent storage capabilities for SONA agents. They handle memory storage, relationship tracking, and knowledge management across different database backends.

## Implementation Notes:

Each adapter optimizes these methods for their specific database backend:

* **MongoDB**: Uses aggregation pipelines for vector operations
* **PostgreSQL**: Leverages pgvector extension
* **SQLite**: Implements BLOB storage for vectors
* **Qdrant**: Optimizes with HNSW indexing
* **Supabase**: Adds real-time capabilities

All adapters provide

```typescript
interface IDatabaseAdapter {
    // Memory Management
    createMemory(memory: Memory, tableName: string): Promise<void>;
    getMemories(params: { roomId: UUID; count?: number }): Promise<Memory[]>;
    searchMemories(params: SearchParams): Promise<Memory[]>;
    removeMemory(memoryId: UUID): Promise<void>;
    
    // Account & Room Management
    createAccount(account: Account): Promise<boolean>;
    getAccountById(userId: UUID): Promise<Account>;
    createRoom(roomId?: UUID): Promise<UUID>;
    getRoom(roomId: UUID): Promise<UUID>;
    
    // Participant Management
    addParticipant(userId: UUID, roomId: UUID): Promise<boolean>;
    getParticipantsForRoom(roomId: UUID): Promise<UUID[]>;
    
    // Knowledge Management
    createKnowledge(knowledge: RAGKnowledgeItem): Promise<void>;
    searchKnowledge(params: SearchParams): Promise<RAGKnowledgeItem[]>;
    
    // Goal Management
    createGoal(goal: Goal): Promise<void>;
    updateGoalStatus(params: { goalId: UUID; status: GoalStatus }): Promise<void>;
}
```

## Adapter Implementaion:

```typescript
// MongoDB
import { MongoDBAdapter } from '@sona/adapter-mongodb';
const mongoAdapter = new MongoDBAdapter({
    uri: process.env.MONGODB_URI,
    dbName: process.env.MONGODB_DB_NAME
});

// PostgreSQL
import { PostgresAdapter } from '@sona/adapter-postgres';
const pgAdapter = new PostgresAdapter({
    connectionString: process.env.POSTGRES_URI
});

// SQLite
import { SqliteDatabaseAdapter } from '@sona/adapter-sqlite';
const sqliteAdapter = new SqliteDatabaseAdapter('path/to/database.db');

// Supabase
import { SupabaseAdapter } from '@sona/adapter-supabase';
const supabaseAdapter = new SupabaseAdapter({
    url: process.env.SUPABASE_URL,
    apiKey: process.env.SUPABASE_API_KEY
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tars.pro/sona-framework/core-concepts/adapters.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
