Docs/AI SDK

Memory

Filtering & Search

Last updated March 3, 2026

Advanced search capabilities, metadata filtering, and hybrid search.

Refine your RAG retrieval with powerful filtering and search controls.

Metadata Filters

Cencori supports MongoDB-style query operators for filtering memories based on their metadata.

Operators

OperatorDescriptionExample
$eqEqual to{ category: 'news' }
$neNot equal to{ status: { $ne: 'archived' } }
$inIn array{ tags: { $in: ['ai', 'ml'] } }
$ninNot in array{ id: { $nin: [1, 2] } }
$gt / $gteGreater than{ year: { $gte: 2023 } }
$lt / $lteLess than{ price: { $lt: 50 } }
$andLogical AND{ $and: [...] }
$orLogical OR{ $or: [...] }

Example

Codetext
const start = await cencori.memory.search({
  namespace: 'products',
  query: 'gaming laptop',
  filter: {
    category: 'electronics',
    price: { $lt: 2000 },
    inStock: true,
    tags: { $in: ['gaming', 'performance'] }
  }
});

By default, Cencori uses Semantic Search (Cosine Similarity). You can enable Hybrid Search to combine vector similarity with keyword matching (BM25).

This is effective for searching specific identifiers like User IDs, error codes, or product names that semantic search might miss.

Codetext
const result = await cencori.memory.search({
  namespace: 'logs',
  query: 'Error 503 on database',
  searchMode: 'hybrid', // Default is 'semantic'
  alpha: 0.7 // Weight for semantic vs keyword (0.0 = keyword only, 1.0 = semantic only)
});

Similarity Threshold

The threshold parameter (0.0 to 1.0) controls how relevant a memory must be to be returned.

  • 0.75+: High relevance (direct answers).
  • 0.50-0.75: Moderate relevance (related context).
  • <0.50: Low relevance (broad topic match).
Codetext
// Strict search
await cencori.memory.search({
  query: 'pricing',
  threshold: 0.8 // Only return high-confidence matches
});