@elizaos/core v0.25.8 / DatabaseAdapter
An abstract class representing a database adapter for managing various entities like accounts, memories, actors, goals, and rooms.
• DB = any
new DatabaseAdapter<
DB
>(circuitBreakerConfig
?):DatabaseAdapter
<DB
>
Creates a new DatabaseAdapter instance with optional circuit breaker configuration.
• circuitBreakerConfig?
Configuration options for the circuit breaker
• circuitBreakerConfig.failureThreshold?: number
Number of failures before circuit opens (defaults to 5)
• circuitBreakerConfig.resetTimeout?: number
Time in ms before attempting to close circuit (defaults to 60000)
• circuitBreakerConfig.halfOpenMaxAttempts?: number
Number of successful attempts needed to close circuit (defaults to 3)
DatabaseAdapter
<DB
>
packages/core/src/database.ts:47
db:
DB
The database instance.
packages/core/src/database.ts:24
protected
circuitBreaker:CircuitBreaker
Circuit breaker instance used to handle fault tolerance and prevent cascading failures. Implements the Circuit Breaker pattern to temporarily disable operations when a failure threshold is reached.
The circuit breaker has three states:
- CLOSED: Normal operation, requests pass through
- OPEN: Failure threshold exceeded, requests are blocked
- HALF_OPEN: Testing if service has recovered
packages/core/src/database.ts:37
abstract
init():Promise
<void
>
Optional initialization method for the database adapter.
Promise
<void
>
A Promise that resolves when initialization is complete.
packages/core/src/database.ts:59
abstract
close():Promise
<void
>
Optional close method for the database adapter.
Promise
<void
>
A Promise that resolves when closing is complete.
packages/core/src/database.ts:65
abstract
getAccountById(userId
):Promise
<Account
>
Retrieves an account by its ID.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the user account to retrieve.
Promise
<Account
>
A Promise that resolves to the Account object or null if not found.
IDatabaseAdapter
.getAccountById
packages/core/src/database.ts:72
abstract
createAccount(account
):Promise
<boolean
>
Creates a new account in the database.
• account: Account
The account object to create.
Promise
<boolean
>
A Promise that resolves when the account creation is complete.
IDatabaseAdapter
.createAccount
packages/core/src/database.ts:79
abstract
getMemories(params
):Promise
<Memory
[]>
Retrieves memories based on the specified parameters.
• params
An object containing parameters for the memory retrieval.
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
• params.count?: number
• params.unique?: boolean
• params.tableName: string
Promise
<Memory
[]>
A Promise that resolves to an array of Memory objects.
packages/core/src/database.ts:86
abstract
getMemoriesByRoomIds(params
):Promise
<Memory
[]>
• params
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.roomIds: `${string}-${string}-${string}-${string}-${string}`[]
• params.tableName: string
• params.limit?: number
Promise
<Memory
[]>
IDatabaseAdapter
.getMemoriesByRoomIds
packages/core/src/database.ts:94
abstract
getMemoryById(id
):Promise
<Memory
>
• id: `${string}-${string}-${string}-${string}-${string}`
Promise
<Memory
>
IDatabaseAdapter
.getMemoryById
packages/core/src/database.ts:101
abstract
getMemoriesByIds(memoryIds
,tableName
?):Promise
<Memory
[]>
Retrieves multiple memories by their IDs
• memoryIds: `${string}-${string}-${string}-${string}-${string}`[]
Array of UUIDs of the memories to retrieve
• tableName?: string
Optional table name to filter memories by type
Promise
<Memory
[]>
Promise resolving to array of Memory objects
IDatabaseAdapter
.getMemoriesByIds
packages/core/src/database.ts:109
abstract
getCachedEmbeddings(params
):Promise
<object
[]>
Retrieves cached embeddings based on the specified query parameters.
• params
An object containing parameters for the embedding retrieval.
• params.query_table_name: string
• params.query_threshold: number
• params.query_input: string
• params.query_field_name: string
• params.query_field_sub_name: string
• params.query_match_count: number
Promise
<object
[]>
A Promise that resolves to an array of objects containing embeddings and levenshtein scores.
IDatabaseAdapter
.getCachedEmbeddings
packages/core/src/database.ts:119
abstract
log(params
):Promise
<void
>
Logs an event or action with the specified details.
• params
An object containing parameters for the log entry.
• params.body
• params.userId: `${string}-${string}-${string}-${string}-${string}`
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
• params.type: string
Promise
<void
>
A Promise that resolves when the log entry has been saved.
packages/core/src/database.ts:145
abstract
getActorDetails(params
):Promise
<Actor
[]>
Retrieves details of actors in a given room.
• params
An object containing the roomId to search for actors.
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
Promise
<Actor
[]>
A Promise that resolves to an array of Actor objects.
IDatabaseAdapter
.getActorDetails
packages/core/src/database.ts:157
abstract
searchMemories(params
):Promise
<Memory
[]>
Searches for memories based on embeddings and other specified parameters.
• params
An object containing parameters for the memory search.
• params.tableName: string
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
• params.embedding: number
[]
• params.match_threshold: number
• params.match_count: number
• params.unique: boolean
Promise
<Memory
[]>
A Promise that resolves to an array of Memory objects.
IDatabaseAdapter
.searchMemories
packages/core/src/database.ts:164
abstract
updateGoalStatus(params
):Promise
<void
>
Updates the status of a specific goal.
• params
An object containing the goalId and the new status.
• params.goalId: `${string}-${string}-${string}-${string}-${string}`
• params.status: GoalStatus
Promise
<void
>
A Promise that resolves when the goal status has been updated.
IDatabaseAdapter
.updateGoalStatus
packages/core/src/database.ts:179
abstract
searchMemoriesByEmbedding(embedding
,params
):Promise
<Memory
[]>
Searches for memories by embedding and other specified parameters.
• embedding: number
[]
The embedding vector to search with.
• params
Additional parameters for the search.
• params.match_threshold?: number
• params.count?: number
• params.roomId?: `${string}-${string}-${string}-${string}-${string}`
• params.agentId?: `${string}-${string}-${string}-${string}-${string}`
• params.unique?: boolean
• params.tableName: string
Promise
<Memory
[]>
A Promise that resolves to an array of Memory objects.
IDatabaseAdapter
.searchMemoriesByEmbedding
packages/core/src/database.ts:190
abstract
createMemory(memory
,tableName
,unique
?):Promise
<void
>
Creates a new memory in the database.
• memory: Memory
The memory object to create.
• tableName: string
The table where the memory should be stored.
• unique?: boolean
Indicates if the memory should be unique.
Promise
<void
>
A Promise that resolves when the memory has been created.
packages/core/src/database.ts:209
abstract
removeMemory(memoryId
,tableName
):Promise
<void
>
Removes a specific memory from the database.
• memoryId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the memory to remove.
• tableName: string
The table from which the memory should be removed.
Promise
<void
>
A Promise that resolves when the memory has been removed.
packages/core/src/database.ts:221
abstract
removeAllMemories(roomId
,tableName
):Promise
<void
>
Removes all memories associated with a specific room.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room whose memories should be removed.
• tableName: string
The table from which the memories should be removed.
Promise
<void
>
A Promise that resolves when all memories have been removed.
IDatabaseAdapter
.removeAllMemories
packages/core/src/database.ts:229
abstract
countMemories(roomId
,unique
?,tableName
?):Promise
<number
>
Counts the number of memories in a specific room.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room for which to count memories.
• unique?: boolean
Specifies whether to count only unique memories.
• tableName?: string
Optional table name to count memories from.
Promise
<number
>
A Promise that resolves to the number of memories.
IDatabaseAdapter
.countMemories
packages/core/src/database.ts:238
abstract
getGoals(params
):Promise
<Goal
[]>
Retrieves goals based on specified parameters.
• params
An object containing parameters for goal retrieval.
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
• params.userId?: `${string}-${string}-${string}-${string}-${string}`
• params.onlyInProgress?: boolean
• params.count?: number
Promise
<Goal
[]>
A Promise that resolves to an array of Goal objects.
packages/core/src/database.ts:249
abstract
updateGoal(goal
):Promise
<void
>
Updates a specific goal in the database.
• goal: Goal
The goal object with updated properties.
Promise
<void
>
A Promise that resolves when the goal has been updated.
packages/core/src/database.ts:262
abstract
createGoal(goal
):Promise
<void
>
Creates a new goal in the database.
• goal: Goal
The goal object to create.
Promise
<void
>
A Promise that resolves when the goal has been created.
packages/core/src/database.ts:269
abstract
removeGoal(goalId
):Promise
<void
>
Removes a specific goal from the database.
• goalId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the goal to remove.
Promise
<void
>
A Promise that resolves when the goal has been removed.
packages/core/src/database.ts:276
abstract
removeAllGoals(roomId
):Promise
<void
>
Removes all goals associated with a specific room.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room whose goals should be removed.
Promise
<void
>
A Promise that resolves when all goals have been removed.
IDatabaseAdapter
.removeAllGoals
packages/core/src/database.ts:283
abstract
getRoom(roomId
):Promise
<`${string}-${string}-${string}-${string}-${string}`>
Retrieves the room ID for a given room, if it exists.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room to retrieve.
Promise
<`${string}-${string}-${string}-${string}-${string}`>
A Promise that resolves to the room ID or null if not found.
packages/core/src/database.ts:290
abstract
createRoom(roomId
?):Promise
<`${string}-${string}-${string}-${string}-${string}`>
Creates a new room with an optional specified ID.
• roomId?: `${string}-${string}-${string}-${string}-${string}`
Optional UUID to assign to the new room.
Promise
<`${string}-${string}-${string}-${string}-${string}`>
A Promise that resolves to the UUID of the created room.
packages/core/src/database.ts:297
abstract
removeRoom(roomId
):Promise
<void
>
Removes a specific room from the database.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room to remove.
Promise
<void
>
A Promise that resolves when the room has been removed.
packages/core/src/database.ts:304
abstract
getRoomsForParticipant(userId
):Promise
<`${string}-${string}-${string}-${string}-${string}`[]>
Retrieves room IDs for which a specific user is a participant.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the user.
Promise
<`${string}-${string}-${string}-${string}-${string}`[]>
A Promise that resolves to an array of room IDs.
IDatabaseAdapter
.getRoomsForParticipant
packages/core/src/database.ts:311
abstract
getRoomsForParticipants(userIds
):Promise
<`${string}-${string}-${string}-${string}-${string}`[]>
Retrieves room IDs for which specific users are participants.
• userIds: `${string}-${string}-${string}-${string}-${string}`[]
An array of UUIDs of the users.
Promise
<`${string}-${string}-${string}-${string}-${string}`[]>
A Promise that resolves to an array of room IDs.
IDatabaseAdapter
.getRoomsForParticipants
packages/core/src/database.ts:318
abstract
addParticipant(userId
,roomId
):Promise
<boolean
>
Adds a user as a participant to a specific room.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the user to add as a participant.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room to which the user will be added.
Promise
<boolean
>
A Promise that resolves to a boolean indicating success or failure.
IDatabaseAdapter
.addParticipant
packages/core/src/database.ts:326
abstract
removeParticipant(userId
,roomId
):Promise
<boolean
>
Removes a user as a participant from a specific room.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the user to remove as a participant.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room from which the user will be removed.
Promise
<boolean
>
A Promise that resolves to a boolean indicating success or failure.
IDatabaseAdapter
.removeParticipant
packages/core/src/database.ts:334
abstract
getParticipantsForAccount(userId
):Promise
<Participant
[]>
Retrieves participants associated with a specific account.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the account.
Promise
<Participant
[]>
A Promise that resolves to an array of Participant objects.
IDatabaseAdapter
.getParticipantsForAccount
packages/core/src/database.ts:341
abstract
getParticipantsForAccount(userId
):Promise
<Participant
[]>
Retrieves participants associated with a specific account.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the account.
Promise
<Participant
[]>
A Promise that resolves to an array of Participant objects.
IDatabaseAdapter.getParticipantsForAccount
packages/core/src/database.ts:348
abstract
getParticipantsForRoom(roomId
):Promise
<`${string}-${string}-${string}-${string}-${string}`[]>
Retrieves participants for a specific room.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room for which to retrieve participants.
Promise
<`${string}-${string}-${string}-${string}-${string}`[]>
A Promise that resolves to an array of UUIDs representing the participants.
IDatabaseAdapter
.getParticipantsForRoom
packages/core/src/database.ts:355
abstract
getParticipantUserState(roomId
,userId
):Promise
<"FOLLOWED"
|"MUTED"
>
• roomId: `${string}-${string}-${string}-${string}-${string}`
• userId: `${string}-${string}-${string}-${string}-${string}`
Promise
<"FOLLOWED"
| "MUTED"
>
IDatabaseAdapter
.getParticipantUserState
packages/core/src/database.ts:357
abstract
setParticipantUserState(roomId
,userId
,state
):Promise
<void
>
• roomId: `${string}-${string}-${string}-${string}-${string}`
• userId: `${string}-${string}-${string}-${string}-${string}`
• state: "FOLLOWED"
| "MUTED"
Promise
<void
>
IDatabaseAdapter
.setParticipantUserState
packages/core/src/database.ts:361
abstract
createRelationship(params
):Promise
<boolean
>
Creates a new relationship between two users.
• params
An object containing the UUIDs of the two users (userA and userB).
• params.userA: `${string}-${string}-${string}-${string}-${string}`
• params.userB: `${string}-${string}-${string}-${string}-${string}`
Promise
<boolean
>
A Promise that resolves to a boolean indicating success or failure of the creation.
IDatabaseAdapter
.createRelationship
packages/core/src/database.ts:372
abstract
getRelationship(params
):Promise
<Relationship
>
Retrieves a relationship between two users if it exists.
• params
An object containing the UUIDs of the two users (userA and userB).
• params.userA: `${string}-${string}-${string}-${string}-${string}`
• params.userB: `${string}-${string}-${string}-${string}-${string}`
Promise
<Relationship
>
A Promise that resolves to the Relationship object or null if not found.
IDatabaseAdapter
.getRelationship
packages/core/src/database.ts:382
abstract
getRelationships(params
):Promise
<Relationship
[]>
Retrieves all relationships for a specific user.
• params
An object containing the UUID of the user.
• params.userId: `${string}-${string}-${string}-${string}-${string}`
Promise
<Relationship
[]>
A Promise that resolves to an array of Relationship objects.
IDatabaseAdapter
.getRelationships
packages/core/src/database.ts:392
abstract
getKnowledge(params
):Promise
<RAGKnowledgeItem
[]>
Retrieves knowledge items based on specified parameters.
• params
Object containing search parameters
• params.id?: `${string}-${string}-${string}-${string}-${string}`
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.limit?: number
• params.query?: string
• params.conversationContext?: string
Promise
<RAGKnowledgeItem
[]>
Promise resolving to array of knowledge items
packages/core/src/database.ts:401
abstract
searchKnowledge(params
):Promise
<RAGKnowledgeItem
[]>
• params
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.embedding: Float32Array
• params.match_threshold: number
• params.match_count: number
• params.searchText?: string
Promise
<RAGKnowledgeItem
[]>
IDatabaseAdapter
.searchKnowledge
packages/core/src/database.ts:409
abstract
createKnowledge(knowledge
):Promise
<void
>
Creates a new knowledge item in the database.
• knowledge: RAGKnowledgeItem
The knowledge item to create
Promise
<void
>
Promise resolving when creation is complete
IDatabaseAdapter
.createKnowledge
packages/core/src/database.ts:422
abstract
removeKnowledge(id
):Promise
<void
>
Removes a knowledge item and its associated chunks from the database.
• id: `${string}-${string}-${string}-${string}-${string}`
The ID of the knowledge item to remove
Promise
<void
>
Promise resolving when removal is complete
IDatabaseAdapter
.removeKnowledge
packages/core/src/database.ts:429
abstract
clearKnowledge(agentId
,shared
?):Promise
<void
>
Removes an agents full knowledge database and its associated chunks from the database.
• agentId: `${string}-${string}-${string}-${string}-${string}`
The Agent ID of the knowledge items to remove
• shared?: boolean
Promise
<void
>
Promise resolving when removal is complete
IDatabaseAdapter
.clearKnowledge
packages/core/src/database.ts:436
protected
withCircuitBreaker<T
>(operation
,context
):Promise
<T
>
Executes an operation with circuit breaker protection.
• T
• operation
A function that returns a Promise to be executed with circuit breaker protection
• context: string
A string describing the context/operation being performed for logging purposes
Promise
<T
>
A Promise that resolves to the result of the operation
Will throw an error if the circuit breaker is open or if the operation fails