mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-19 16:13:19 +00:00
pkg(tools): Expose raw search results in MemoryPromptData for prompt templates (#787)
Expose raw search results in `MemoryPromptData` so prompt templates can traverse, filter, and selectively include results based on metadata (e.g. score, source).
##### Usage example
```typescript
const promptTemplate = (data: MemoryPromptData) => {
const relevant = data.searchResults.filter(
(r) => (r.metadata?.score as number) > 0.7
)
return `${data.userMemories}\n${relevant.map(r => r.memory).join('\n')}`
}
```
This commit is contained in:
parent
c534008001
commit
a00a751e10
8 changed files with 40 additions and 8 deletions
|
|
@ -154,6 +154,7 @@ export const buildMemoriesText = async (
|
|||
const promptData: MemoryPromptData = {
|
||||
userMemories,
|
||||
generalSearchMemories,
|
||||
searchResults: memoriesResponse.searchResults?.results ?? [],
|
||||
}
|
||||
|
||||
const memories = promptTemplate(promptData)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,12 @@ export interface MemoryPromptData {
|
|||
* Empty string if mode is "profile" only.
|
||||
*/
|
||||
generalSearchMemories: string
|
||||
/**
|
||||
* Raw search results from the API for the current query.
|
||||
* Use this to traverse, filter, or selectively include results based on metadata.
|
||||
* Empty array if mode is "profile" or when no search was performed.
|
||||
*/
|
||||
searchResults: Array<{ memory: string; metadata?: Record<string, unknown> }>
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -28,6 +34,7 @@ export interface MemoryPromptData {
|
|||
* ${data.generalSearchMemories}
|
||||
* </user_memories>
|
||||
* `.trim()
|
||||
* // data.searchResults provides raw results for custom filtering/formatting
|
||||
* ```
|
||||
*/
|
||||
export type PromptTemplate = (data: MemoryPromptData) => string
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export {
|
|||
type BuildMemoriesTextOptions,
|
||||
} from "../shared"
|
||||
|
||||
import type { Logger } from "../shared"
|
||||
import type { Logger, MemoryPromptData } from "../shared"
|
||||
import type { LanguageModelCallOptions } from "./util"
|
||||
|
||||
/**
|
||||
|
|
@ -100,10 +100,7 @@ export const addSystemPrompt = async (
|
|||
mode: "profile" | "query" | "full",
|
||||
baseUrl: string,
|
||||
apiKey: string,
|
||||
promptTemplate?: (data: {
|
||||
userMemories: string
|
||||
generalSearchMemories: string
|
||||
}) => string,
|
||||
promptTemplate?: (data: MemoryPromptData) => string,
|
||||
): Promise<LanguageModelCallOptions> => {
|
||||
const { buildMemoriesText } = await import("../shared")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue