Skip to main content

Querying

Remem offers two query modes optimized for different use cases: Fast for low-latency retrieval and Rich for comprehensive LLM-powered answers.

Query Modes Overview

Fast Mode

Target: <100ms Best for: Agent context injection, real-time lookups, high-volume automationReturns raw ranked results using hybrid BM25 + vector search with no LLM overhead.

Rich Mode

Target: <2s (budget-aware) Best for: User-facing Q&A, research queries, complex questionsAdds query expansion, reranking, and optional LLM synthesis with citations.
Tradeoff: Fast mode prioritizes speed for high-volume agent queries. Rich mode sacrifices latency for deeper understanding and synthesis, ideal for interactive use.

POST /v1/query

The primary query endpoint supports both modes.

Minimal Fast Query

Rich Query with Synthesis

Request Parameters

Query length limits: Max 2000 characters (~500 tokens). Longer queries may be truncated or rejected.

GET /v1/search

Convenience endpoint for fast-mode search via query parameters.

Query Parameters

This endpoint is equivalent to POST /v1/query with mode: "fast" and no filters. Use it for simple integrations.

Namespace Scope

Querying is namespace-aware. Namespace scope is applied before results are returned. Sensitivity scope is still enforced on top of that.

Query one namespace

Query several namespaces

Query all readable namespaces explicitly


How Fast Mode Works

Fast mode uses hybrid retrieval to combine lexical and semantic search.
1

Embed Query

User query → voyage-3.5-lite embedding (cached for 30 min)
2

Parallel Retrieval

  • Vector Search: Qdrant cosine similarity on embeddings
  • BM25 Keyword Search: PostgreSQL full-text search on tsvector index
3

Reciprocal Rank Fusion (RRF)

Merge results from both systems using weighted RRF:
This balances semantic understanding (vector) with exact keyword matches (BM25).
4

Decrypt & Return

Fetch top-ranked chunks from PostgreSQL, decrypt content, and return results with scores.
Why hybrid? Vector search excels at semantic similarity (“outstanding bills” ~ “unpaid invoices”), while BM25 catches exact keyword matches (e.g., “invoice #12345”). RRF combines the best of both.
PageIndex is not used in fast mode. It is only blended into rich mode to enhance long-document retrieval.

How Rich Mode Works

Rich mode extends fast mode with query understanding and LLM synthesis.
1

Query Expansion (Grok)

Generates 2 variant queries to catch different phrasings:
  • Original: “What are our Q1 priorities?”
  • Variant 1: “first quarter objectives 2026”
  • Variant 2: “goals for January through March”
2

Parallel Retrieval

Runs hybrid search for original + expanded queries concurrently.
3

RRF Multi-Fusion

Merges all result lists:
  • Original query results weighted 2x
  • Expansion variants weighted 1x each
4

LLM Reranking (Grok)

Rescores top 30 candidates by semantic relevance to the original query.
5

PageIndex Node Selection (Optional)

For long PDFs and Markdown files that have a PageIndex tree, Remem reranks the node summaries and attaches the top nodes (default: 2 per document) to the candidate set. This helps synthesis cite the most relevant sections in very long documents.
6

LLM Synthesis (Grok, optional)

If synthesize: true, writes a concise answer with [1], [2] source citations.
7

Budget-Aware Cutoff

If time budget is exhausted, skips rerank/synthesis and returns fast results.
Caching: Expansion and rerank results are cached in Redis for 15 minutes. Repeated queries on similar topics are ~3x faster (~3s vs ~8s cold start).

Filters

Filters narrow search scope using document metadata assigned during classification.

Available Filters

Dynamic categories and tags: Unlike traditional systems, Remem doesn’t use predefined categories. The LLM classifier assigns categories and tags based on content, so they vary by document.

Filtered Query Example

Filter to meeting notes from the last week:

Combining Filters

Filters are applied with AND logic. Example: confidential invoices from Amazon in Q4 2025:

Session-Memory Filter Example

Retrieve only one coding session’s checkpoints:

Response Structure

Fast Mode Response

Rich Mode Response with Synthesis

Response Fields

Scores: Relevance scores range from 0 to 1. Scores above 0.7 typically indicate strong matches. Scores below 0.5 may be tangentially related.

Querying with Facts

When the Memory Layer is enabled, queries can return extracted facts alongside document chunks.

Request Parameters

Example: Query with Facts

Response with Facts

The response includes a facts array and fact_count alongside the normal results:

Fact Response Fields

Entity and Fact Browsing Endpoints

In addition to querying, you can browse entities and their facts directly:

Sensitivity Scoping

API keys have a maximum sensitivity level that automatically filters query results.

Sensitivity Hierarchy

How It Works

  • Automatic filtering: A key with internal max sensitivity will never see confidential or personal documents, even if explicitly requested via filters.
  • The sensitivity filter further narrows within the key’s allowed scope.
  • Example: A key with internal max can filter to ["public"] or ["public", "internal"], but not ["confidential"].
Key created with max_sensitivity: "public":
This key can only access documents classified as public. All queries automatically filter to sensitivity: ["public"].
Key with max_sensitivity: "internal" can explicitly request public docs:
This returns only public documents, even though the key could access internal docs.
Scope violations: Attempting to query documents above your key’s sensitivity level will return an empty result set, not an error. Check your API key’s max_sensitivity if you’re not seeing expected results.

Tips and Best Practices

Use Fast Mode for Agents

Fast mode’s <500ms latency makes it ideal for:
  • Agent context injection (MCP, tool calls)
  • Real-time autocomplete
  • High-volume background jobs

Use Rich Mode for Humans

Rich mode with synthesis is perfect for:
  • User-facing Q&A interfaces
  • Research and deep dives
  • Complex multi-part questions

Query Design

Be specific: “Q1 2026 budget meeting action items” is better than “meetings”.
Combine filters: Narrow scope with category + date range + tags for precision. Example: category: "invoice" + tags_any: ["vendor:amazon"] + date_from: "2025-12-01".
Scores matter: Results are ranked by relevance. Scores above 0.7 are typically strong matches. Review lower-scoring results carefully.

Troubleshooting Empty Results

Documents are ingested asynchronously. Check the job status or wait a few seconds after ingestion before querying.
If your key has max_sensitivity: "internal", it can’t see confidential or personal docs. Check the key’s scoping.
Try removing filters one by one to see which is excluding results. Categories and tags are LLM-assigned and may not match your expectations.
Very broad queries (“meetings”) may return low scores. Very narrow queries (“invoice #12345 from Amazon on Jan 15”) may miss documents if metadata doesn’t match exactly.

Performance Optimization

Cache benefits: Rich mode benefits heavily from caching. The second query on similar topics is ~3x faster (~3s vs ~8s cold).
Limit results: Request only what you need. Fetching 100 results is slower than fetching 10.
Use filters: Pre-filtering with category/tags/sensitivity at the vector search level is faster than post-filtering in your application.

Next Steps