1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
---
title: "Extend Provider"
description: "Add a custom memory provider to MemoryBench"
sidebarTitle: "Extend Provider"
---
## Provider Interface
```typescript
interface Provider {
name: string
prompts?: ProviderPrompts
initialize(config: ProviderConfig): Promise<void>
ingest(sessions: UnifiedSession[], options: IngestOptions): Promise<IngestResult>
awaitIndexing(result: IngestResult, containerTag: string): Promise<void>
search(query: string, options: SearchOptions): Promise<unknown[]>
clear(containerTag: string): Promise<void>
}
```
---
## Adding a Custom Provider
### 1. Create the Provider
```typescript
// src/providers/myprovider/index.ts
import type { Provider, ProviderConfig, UnifiedSession } from "../../types"
export class MyProvider implements Provider {
name = "myprovider"
private client: MyClient | null = null
async initialize(config: ProviderConfig) {
this.client = new MyClient({ apiKey: config.apiKey })
}
async ingest(sessions: UnifiedSession[], options: IngestOptions) {
const documentIds: string[] = []
for (const session of sessions) {
const response = await this.client.add({
content: JSON.stringify(session.messages),
metadata: session.metadata
})
documentIds.push(response.id)
}
return { documentIds }
}
async awaitIndexing(result: IngestResult) {
// Poll until indexing complete
}
async search(query: string, options: SearchOptions) {
return await this.client.search({ q: query, limit: 10 })
}
async clear(containerTag: string) {
await this.client.delete(containerTag)
}
}
```
### 2. Register the Provider
```typescript
// src/providers/index.ts
import { MyProvider } from "./myprovider"
export const providers = {
supermemory: SupermemoryProvider,
mem0: Mem0Provider,
zep: ZepProvider,
myprovider: MyProvider, // Add here
}
```
### 3. Add Configuration
```typescript
// src/utils/config.ts
case "myprovider":
return {
apiKey: process.env.MYPROVIDER_API_KEY!,
}
```
---
## Custom Prompts
Providers can define custom answer and judge prompts for better results.
```typescript
// src/providers/myprovider/prompts.ts
export const MY_PROMPTS: ProviderPrompts = {
answerPrompt: (question, context, questionDate) => {
return `Based on context:\n${context}\n\nAnswer: ${question}`
},
judgePrompt: (question, groundTruth, hypothesis) => ({
default: "Compare answer to ground truth...",
temporal: "Allow off-by-one for dates...",
adversarial: "Check if model correctly abstained...",
})
}
```
Then reference in your provider:
```typescript
export class MyProvider implements Provider {
name = "myprovider"
prompts = MY_PROMPTS // Custom prompts
// ...
}
```
|