Skip to content

Commit 3bdf7d3

Browse files
fixed documentDelete bug
1 parent 0a0697e commit 3bdf7d3

10 files changed

Lines changed: 363 additions & 139 deletions

File tree

apps/docs/ai-sdk/user-profiles.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,32 @@ const result = await generateText({
117117
// Uses both profile (user's expertise) AND search (previous debugging sessions)
118118
```
119119

120+
### Hybrid Search Mode
121+
122+
Use `searchMode: "hybrid"` to search both memories AND document chunks.
123+
124+
```typescript
125+
const model = withSupermemory(openai("gpt-4"), "user-123", {
126+
mode: "full",
127+
searchMode: "hybrid", // Search memories + document chunks
128+
searchLimit: 15 // Max results (default: 10)
129+
})
130+
131+
const result = await generateText({
132+
model,
133+
messages: [{
134+
role: "user",
135+
content: "What's in my documents about quarterly goals?"
136+
}]
137+
})
138+
// Searches both extracted memories AND raw document content
139+
```
140+
141+
**Search Mode Options:**
142+
- `"memories"` (default) - Search only memory entries
143+
- `"hybrid"` - Search memories + document chunks
144+
- `"documents"` - Search only document chunks
145+
120146
## Custom Prompt Templates
121147

122148
Customize how memories are formatted and injected into the system prompt using the `promptTemplate` option. This is useful for:

packages/tools/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,29 @@ const result = await generateText({
184184
})
185185
```
186186

187+
**Hybrid Search Mode (RAG)** - Search both memories AND document chunks:
188+
```typescript
189+
import { generateText } from "ai"
190+
import { withSupermemory } from "@supermemory/tools/ai-sdk"
191+
import { openai } from "@ai-sdk/openai"
192+
193+
const modelWithHybrid = withSupermemory(openai("gpt-4"), "user-123", {
194+
mode: "full",
195+
searchMode: "hybrid", // Search memories + document chunks
196+
searchLimit: 15 // Max results (default: 10)
197+
})
198+
199+
const result = await generateText({
200+
model: modelWithHybrid,
201+
messages: [{ role: "user", content: "What's in my documents about quarterly goals?" }],
202+
})
203+
```
204+
205+
Search mode options:
206+
- `"memories"` (default) - Search only memory entries
207+
- `"hybrid"` - Search memories + document chunks (recommended for RAG)
208+
- `"documents"` - Search only document chunks
209+
187210
#### Automatic Memory Capture
188211

189212
The middleware can automatically save user messages as memories:
@@ -652,6 +675,8 @@ interface WithSupermemoryOptions {
652675
conversationId?: string
653676
verbose?: boolean
654677
mode?: "profile" | "query" | "full"
678+
searchMode?: "memories" | "hybrid" | "documents"
679+
searchLimit?: number
655680
addMemory?: "always" | "never"
656681
/** Optional Supermemory API key. Use this in browser environments. */
657682
apiKey?: string
@@ -661,6 +686,8 @@ interface WithSupermemoryOptions {
661686
- **conversationId**: Optional conversation ID to group messages into a single document for contextual memory generation
662687
- **verbose**: Enable detailed logging of memory search and injection process (default: false)
663688
- **mode**: Memory search mode - "profile" (default), "query", or "full"
689+
- **searchMode**: Search mode - "memories" (default), "hybrid", or "documents". Use "hybrid" for RAG applications
690+
- **searchLimit**: Maximum number of search results when using hybrid/documents mode (default: 10)
664691
- **addMemory**: Automatic memory storage mode - "always" or "never" (default: "never")
665692

666693
## Available Tools

packages/tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@supermemory/tools",
33
"type": "module",
4-
"version": "1.4.00",
4+
"version": "1.5.0",
55
"description": "Memory tools for AI SDK and OpenAI function calling with supermemory",
66
"scripts": {
77
"build": "tsdown",

packages/tools/src/ai-sdk.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -232,38 +232,6 @@ export const documentListTool = (
232232
})
233233
}
234234

235-
export const documentDeleteTool = (
236-
apiKey: string,
237-
config?: SupermemoryToolsConfig,
238-
) => {
239-
const client = new Supermemory({
240-
apiKey,
241-
...(config?.baseUrl ? { baseURL: config.baseUrl } : {}),
242-
})
243-
244-
return tool({
245-
description: TOOL_DESCRIPTIONS.documentDelete,
246-
inputSchema: z.object({
247-
documentId: z.string().describe(PARAMETER_DESCRIPTIONS.documentId),
248-
}),
249-
execute: async ({ documentId }) => {
250-
try {
251-
await client.documents.delete({ docId: documentId })
252-
253-
return {
254-
success: true,
255-
message: `Document ${documentId} deleted successfully`,
256-
}
257-
} catch (error) {
258-
return {
259-
success: false,
260-
error: error instanceof Error ? error.message : "Unknown error",
261-
}
262-
}
263-
},
264-
})
265-
}
266-
267235
export const documentAddTool = (
268236
apiKey: string,
269237
config?: SupermemoryToolsConfig,
@@ -383,7 +351,6 @@ export function supermemoryTools(
383351
addMemory: addMemoryTool(apiKey, config),
384352
getProfile: getProfileTool(apiKey, config),
385353
documentList: documentListTool(apiKey, config),
386-
documentDelete: documentDeleteTool(apiKey, config),
387354
documentAdd: documentAddTool(apiKey, config),
388355
memoryForget: memoryForgetTool(apiKey, config),
389356
}

packages/tools/src/shared/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type {
33
MemoryPromptData,
44
PromptTemplate,
55
MemoryMode,
6+
SearchMode,
67
AddMemoryMode,
78
Logger,
89
ProfileStructure,
@@ -34,9 +35,12 @@ export {
3435
// Memory client
3536
export {
3637
supermemoryProfileSearch,
38+
supermemoryHybridSearch,
3739
buildMemoriesText,
3840
extractQueryText,
3941
getLastUserMessageText,
4042
type BuildMemoriesTextOptions,
4143
type GenericMessage,
44+
type SearchResultItem,
45+
type SearchResponse,
4246
} from "./memory-client"

0 commit comments

Comments
 (0)