SDKs
Node.js SDK
Works in Node.js 18+ and browsers.
Default API: https://api.databaset.com
Installation
npm install @databaset/sdkRequirements
- Node.js 18+ (or a browser with
fetch) DATABASET_API_KEYenvironment variable (Node) or passapiKeyin options
Initialize
import { Memory } from '@databaset/sdk'
const memory = new Memory()
// or:
// new Memory({ apiKey: 'db_...', appId: 'my-app', baseUrl: 'https://api.databaset.com' })Environment variables (Node):
| Variable | Description |
|----------|-------------|
| DATABASET_API_KEY | API key (db_...) |
| DATABASET_API_URL | Optional API base URL (default: production) |
Browser
<script src="https://api.databaset.com/sdk/databaset.js"></script>
<script>
const memory = new Databaset.Memory({
apiKey: 'db_...',
baseUrl: 'https://api.databaset.com',
})
</script>Or from npm: https://unpkg.com/@databaset/sdk/dist/databaset.browser.js
memory.store()
await memory.store({
userId: string, // required
text: string, // required
appId?: string, // optional; falls back to constructor appId or key-bound app
metadata?: object,
})
// Returns: { id, userId, appId, createdAt }memory.recall()
const context = await memory.recall({
userId: string,
query: string,
appId?: string,
limit?: number, // default: 5, max: 100
minScore?: number, // default: 0.7
})
// Returns: string contextmemory.recallRaw()
const memories = await memory.recallRaw({
userId: string,
query: string,
limit?: number,
minScore?: number,
})
// Returns: [{ id, text, score, createdAt }]memory.forget()
// Delete one memory by short id or UUID
await memory.forget('mem_abc12345')memory.forgetUser()
await memory.forgetUser({ userId: 'user_123', appId: 'my-app' })memory.forgetBulk()
await memory.forgetBulk(['mem_abc12345', 'mem_def67890'])memory.list()
const { memories, total, page, pageSize } = await memory.list({
userId: string, // required in SDK
appId?: string,
page?: number, // default: 0
pageSize?: number, // default: 20, max: 100
})Error handling
import { DatabasetError, ValidationError } from '@databaset/sdk'
try {
await memory.store({ userId, text })
} catch (err) {
if (err instanceof ValidationError) {
console.error('Invalid input:', err.message)
} else if (err instanceof DatabasetError) {
console.error('API error:', err.message, err.status)
}
}API errors use DatabasetError with status and code properties.