Skip to content

feat: add POST /query endpoint for structured SQL-like queries #658

Closed

Description

@ajianaz

Summary

Uteke only supports semantic search (/recall) and keyword search (/search). No way to perform structured queries like:

  • WHERE memory_type = 'decision' AND namespace = 'cmo'
  • WHERE importance > 0.5 AND created_at > '2026-07-01'
  • WHERE json_extract(metadata, '$.platform') = 'threads'

Proposed Endpoint

POST /query
{
  "namespace": "cmo",
  "memory_type": "fact",
  "tags": ["threads"],
  "importance_min": 0.5,
  "created_after": "2026-07-01",
  "metadata_filters": {"platform": "threads"},
  "order_by": "created_at",
  "order_dir": "desc",
  "limit": 20
}

Acceptance Criteria

Functional

  • New POST /query endpoint accepting structured filter parameters
  • Supports column filters: namespace, memory_type, tags, importance range, date range, pinned, deprecated
  • Supports metadata JSON filters via json_extract
  • ORDER BY + LIMIT + OFFSET pagination
  • Returns same memory format as /list

Verification (CMO can run without reading code)

  • curl POST /query {"namespace":"cmo","memory_type":"fact","limit":5} → returns up to 5 memories, all namespace=cmo and type=fact
  • curl POST /query {"tags":["codecoradev","threads"]} → returns memories with BOTH tags (AND logic)
  • curl POST /query {"importance_min":0.5,"importance_max":1.0} → only memories in range
  • curl POST /query {"created_after":"2026-01-01","order_by":"created_at","order_dir":"desc"} → chronologically sorted, after date
  • curl POST /query {"metadata_filters":{"platform":"threads"}} → only memories with that metadata key-value
  • curl POST /query {"limit":5,"offset":5} → returns 2nd page (different from offset=0)
  • curl POST /query with empty body {} → returns all memories (no filter = no constraint)
  • curl POST /query {"memory_type":"nonexistent"} → returns empty array [], not error
  • Response format matches /list output (same JSON shape)

Error handling

  • Invalid JSON body → 400 with clear error message
  • Invalid date format → 400 with clear error message
  • Negative limit/offset → 400 validation error

Tests

  • Unit: query with namespace + memory_type filter → correct subset
  • Unit: query with metadata_filters → json_extract works
  • Integration: pagination offset/limit returns correct slices

Priority

High — essential for using Uteke as dual semantic + structured store.

Dependencies

Activity

  1. added
    enhancement
    priority:high
    scope:api
    on Jul 14, 2026
  2. ajianaz commented on Jul 14, 2026

    @ajianaz
    CollaboratorAuthor

    Dependencies

  3. ajianaz commented on Jul 14, 2026

    @ajianaz
    CollaboratorAuthor

    Duplicate of #668 (same scope, newer issue)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:highscope:api

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions