Skip to main content

POST /memory/search

Search memories based on a query using semantic similarity. Returns relevant memories with similarity scores. Optionally filter results by memory type.

Request Body

query
string
required
The search query. The API will find memories semantically similar to this query.
user_id
string
required
Unique identifier for the user whose memories to search.
limit
integer
default:"10"
Maximum number of results to return. Defaults to 10.
memory_type
string
Filter results by memory type. Accepts: LONG_TERM, SHORT_TERM, EPISODIC, SEMANTIC, or PROCEDURAL.

Response

success
boolean
Indicates whether the operation was successful.
results
array
Array of matching memories sorted by relevance.

Example Request

curl -X POST http://localhost:8000/memory/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What are my UI preferences?",
    "user_id": "user_123",
    "limit": 5
  }'

Example Response

{
  "success": true,
  "results": [
    {
      "id": "mem_abc123",
      "memory": "User prefers dark mode in applications",
      "score": 0.92,
      "metadata": {
        "memory_type": "LONG_TERM"
      },
      "user_id": "user_123",
      "created_at": "2026-03-01T10:30:00Z",
      "updated_at": "2026-03-01T10:30:00Z"
    },
    {
      "id": "mem_def456",
      "memory": "User likes minimal UI designs with high contrast",
      "score": 0.87,
      "metadata": {
        "memory_type": "LONG_TERM"
      },
      "user_id": "user_123",
      "created_at": "2026-02-28T14:20:00Z",
      "updated_at": "2026-02-28T14:20:00Z"
    }
  ]
}

Filtering by Memory Type

Search only for episodic memories (past events):
curl -X POST http://localhost:8000/memory/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "conferences I attended",
    "user_id": "user_123",
    "memory_type": "EPISODIC",
    "limit": 10
  }'

Search Short-Term Memories

Find what the user is currently working on:
curl -X POST http://localhost:8000/memory/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "current tasks",
    "user_id": "user_123",
    "memory_type": "SHORT_TERM"
  }'

Error Responses

detail
string
Error message describing what went wrong.
500 Internal Server Error
{
  "detail": "Failed to execute search query"
}

Implementation Details

  • Source: backend/main.py:221
  • Search Method: Semantic similarity using vector embeddings
  • Index: Supabase HNSW index with cosine distance
  • Filtering: Supports metadata-based filtering for memory_type and custom fields

Build docs developers (and LLMs) love