Skip to content

pkg(tools): Expose raw search results in MemoryPromptData for prompt templates#787

Merged
graphite-app[bot] merged 1 commit intomainfrom
03-18-pkg_tools_expose_raw_search_results_in_memorypromptdata_for_prompt_templates
Mar 19, 2026
Merged

pkg(tools): Expose raw search results in MemoryPromptData for prompt templates#787
graphite-app[bot] merged 1 commit intomainfrom
03-18-pkg_tools_expose_raw_search_results_in_memorypromptdata_for_prompt_templates

Conversation

@MaheshtheDev
Copy link
Member

@MaheshtheDev MaheshtheDev commented Mar 18, 2026

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
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')}`
}

@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🕒 Queued supermemory-mcp bafe6ff Mar 18 2026, 05:51 PM

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 18, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app a00a751 Mar 19 2026, 12:42 AM

Copy link
Member Author


How to use the Graphite Merge Queue

Add the label Main to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link

claude bot commented Mar 18, 2026

Claude finished @MaheshtheDev's task in 1m 41s —— View job


Code Review Complete

  • Get PR diff and understand changes
  • Review code for bugs and security issues
  • Check surrounding code context
  • Submit review

Overview: Adds a searchResults field to MemoryPromptData exposing raw API search results with metadata for custom filtering in prompt templates.

Issues found: None — this looks good to ship.

The implementation is clean:

  • Type Array<{ memory: string; metadata?: Record<string, unknown> }> correctly matches ProfileStructure.searchResults.results
  • Null safety handled properly with memoriesResponse.searchResults?.results ?? []
  • Clear distinction between generalSearchMemories (deduplicated, pre-formatted string) and searchResults (raw data with metadata) gives users flexibility
  • Documentation accurately reflects the new capability
  • Version bump to 1.4.01 is appropriate for this additive change

Score: 10/10

Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: Adds a searchResults field to MemoryPromptData exposing raw API search results with metadata for custom filtering in prompt templates.

Issues found: None — this looks good to ship.

The implementation is clean:

  • Type Array<{ memory: string; metadata?: Record<string, unknown> }> correctly matches ProfileStructure.searchResults.results
  • Null safety handled properly with memoriesResponse.searchResults?.results ?? []
  • Clear distinction between generalSearchMemories (deduplicated, pre-formatted string) and searchResults (raw data with metadata) gives users flexibility
  • Documentation accurately reflects the new capability
  • Version bump to 1.4.01 is appropriate for this additive change
  • Type cleanup in memory-prompt.ts using MemoryPromptData instead of inline type is a nice improvement

Score: 10/10

@graphite-app
Copy link

graphite-app bot commented Mar 19, 2026

Merge activity

…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')}`
}
```
@graphite-app graphite-app bot force-pushed the 03-18-pkg_tools_expose_raw_search_results_in_memorypromptdata_for_prompt_templates branch from 11dc404 to a00a751 Compare March 19, 2026 00:38
@graphite-app graphite-app bot merged commit a00a751 into main Mar 19, 2026
8 of 9 checks passed
</user_memories>
<relevant_context>
${relevant.map((r) => `- ${r.memory}`).join("\n")}
</relevant_context>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The documentation example for filtering search results uses r.metadata?.score, but the API returns the score in the top-level similarity field, causing the filter to fail.
Severity: MEDIUM

Suggested Fix

Update the documentation example in apps/docs/ai-sdk/user-profiles.mdx to filter by r.similarity instead of r.metadata?.score. The corrected code should be const relevant = data.searchResults.filter((r) => r.similarity > 0.7).

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: apps/docs/ai-sdk/user-profiles.mdx#L198

Potential issue: The documentation example for filtering memory search results
incorrectly references `r.metadata?.score`. The actual API response places the
similarity score in a top-level `similarity` field. As a result, any user code following
this example will have the filter condition `(r.metadata?.score as number) > 0.7`
evaluate to `false`, because `r.metadata?.score` is `undefined`. This will cause all
search results to be filtered out, leading to an empty `relevant` array and preventing
the intended user profile information from being included in the prompt.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants