---
title: "Search memory graph"
description: "Search the user's knowledge graph for relevant facts and entities.\n\nUses hybrid retrieval (BM25 + cosine + graph traversal + cross-encoder\nreranking) to find the most relevant memory edges."
---

> Documentation Index
> Fetch the complete documentation index at: https://truememory-docs.mvstg.com/llms.txt
> Use this file to discover all available pages before exploring further.

Path: AI Gateway API › Memory

`POST /memories/search`

Search the user's knowledge graph for relevant facts and entities.

Uses hybrid retrieval (BM25 + cosine + graph traversal + cross-encoder
reranking) to find the most relevant memory edges.

## Authentication

- `HTTPBearer`, http, header `Authorization`

## Header parameters

- `X-On-Behalf-Of` (`search_memories.header.X-On-Behalf-Of`; any of, optional)
  - any of: `string`, `null`
- `X-External-User-Id` (`search_memories.header.X-External-User-Id`; any of, optional)
  - any of: `string`, `null`
- `X-App-Id` (`search_memories.header.X-App-Id`; any of, optional)
  - any of: `string`, `null`

## Request body

_Required._

- `query` (`search_memories.query`; string, required)
  - minLength 1; maxLength 5000
- `agent_id` (`search_memories.agent_id`; string, required)
- `max_results` (`search_memories.max_results`; integer, optional)
  - min 1; max 50; default `10`
- `created_after` (`search_memories.created_after`; any of, optional) — Only return memories created after this datetime
  - any of: `string`, `null`
- `created_before` (`search_memories.created_before`; any of, optional) — Only return memories created before this datetime
  - any of: `string`, `null`
- `graph_ids` (`search_memories.graph_ids`; any of, optional) — Shared knowledge graphs to blend into the search alongside the user's own memory. Results from these come back tagged scope="graph" with their graph_id.
  - any of: `array<string>`, `null`
- `visibility` (`search_memories.visibility`; any of, optional) — Optional. Keep only facts whose both endpoint nodes carry this visibility — 'public' therefore returns facts that expose no private node, which is what makes them safe to surface outside the owner's private view. Omit for no visibility filtering. Every result reports source_visibility and target_visibility regardless, so you can filter on your own terms instead.
  - any of: `string`, `null`

## Example request

```json
{
  "query": "string",
  "agent_id": "string",
  "max_results": 10,
  "created_after": "2019-08-24T14:15:22Z",
  "created_before": "2019-08-24T14:15:22Z",
  "graph_ids": [
    "string"
  ],
  "visibility": "private"
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url https://truememory-api.mvstg.com/memories/search \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "query": "string",
  "agent_id": "string",
  "max_results": 10,
  "created_after": "2019-08-24T14:15:22Z",
  "created_before": "2019-08-24T14:15:22Z",
  "graph_ids": [
    "string"
  ],
  "visibility": "private"
}
'
```

### TypeScript

```typescript
const url = 'https://truememory-api.mvstg.com/memories/search';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    query: 'string',
    agent_id: 'string',
    max_results: 10,
    created_after: '2019-08-24T14:15:22Z',
    created_before: '2019-08-24T14:15:22Z',
    graph_ids: ['string'],
    visibility: 'private'
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://truememory-api.mvstg.com/memories/search"

payload = {
    "query": "string",
    "agent_id": "string",
    "max_results": 10,
    "created_after": "2019-08-24T14:15:22Z",
    "created_before": "2019-08-24T14:15:22Z",
    "graph_ids": ["string"],
    "visibility": "private"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

Successful Response

#### Example

```json
[
  {
    "id": "string",
    "name": "string",
    "content": "string",
    "created_at": "string",
    "valid_at": "string",
    "source_name": "string",
    "target_name": "string",
    "source_labels": [
      "string"
    ],
    "target_labels": [
      "string"
    ],
    "source_descriptions": [
      "string"
    ],
    "source_visibility": "private",
    "target_visibility": "private",
    "scope": "user",
    "graph_id": "string"
  }
]
```

- `id` (`search_memories.response.200.id`; string, required)
- `name` (`search_memories.response.200.name`; string, required)
- `content` (`search_memories.response.200.content`; string, required)
- `created_at` (`search_memories.response.200.created_at`; any of, required)
  - any of: `string`, `null`
- `valid_at` (`search_memories.response.200.valid_at`; any of, required)
  - any of: `string`, `null`
- `source_name` (`search_memories.response.200.source_name`; any of, required)
  - any of: `string`, `null`
- `target_name` (`search_memories.response.200.target_name`; any of, required)
  - any of: `string`, `null`
- `source_labels` (`search_memories.response.200.source_labels`; array<string>, required)
- `target_labels` (`search_memories.response.200.target_labels`; array<string>, required)
- `source_descriptions` (`search_memories.response.200.source_descriptions`; array<string>, required)
- `source_visibility` (`search_memories.response.200.source_visibility`; string, required)
  - one of `"private"`, `"public"`
- `target_visibility` (`search_memories.response.200.target_visibility`; string, required)
  - one of `"private"`, `"public"`
- `scope` (`search_memories.response.200.scope`; string, required)
  - one of `"user"`, `"graph"`
- `graph_id` (`search_memories.response.200.graph_id`; any of, required) — Set only when scope is graph.
  - any of: `string`, `null`

### 422

Validation Error

#### Example

```json
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string",
      "input": null,
      "ctx": {}
    }
  ]
}
```

- `detail` (`search_memories.response.422.detail`; array<object>, optional)
  - `loc` (`search_memories.response.422.detail.loc`; array<any of>, required)
    - any of: `string`, `integer`
  - `msg` (`search_memories.response.422.detail.msg`; string, required)
  - `type` (`search_memories.response.422.detail.type`; string, required)
  - `input` (`search_memories.response.422.detail.input`; unknown, optional)
  - `ctx` (`search_memories.response.422.detail.ctx`; object, optional)


Source: https://truememory-docs.mvstg.com/api/memories/search/index.md
