MemNexus
GuidesUsing the SDK

Search

Find memories programmatically using semantic, keyword, or hybrid search.

The SDK provides access to MemNexus's hybrid search pipeline — combining vector similarity with full-text matching for accurate results.

const results = await client.memories.search({
  query: "deployment issues",
  limit: 10,
});

for (const result of results.data) {
  console.log(`[${result.score.toFixed(2)}] ${result.memory.content}`);
}

This runs a hybrid search by default. The query is embedded using OpenAI, compared against memory embeddings via cosine similarity, and merged with keyword matches using Reciprocal Rank Fusion (RRF).

Search with filters

Filter by topics

// Only memories with these topics
const results = await client.memories.search({
  query: "authentication",
  topics: ["implementation", "completed"],
  limit: 10,
});

Exclude topics

const results = await client.memories.search({
  query: "debugging",
  excludeTopics: ["meeting-notes"],
  limit: 10,
});

Time-based filtering

const results = await client.memories.search({
  query: "deployments",
  recent: "7d", // 24h, 7d, 2w, 30d
  limit: 10,
});

GraphRAG queries

For complex queries that benefit from traversing the knowledge graph:

// Graph-based query
const graphResults = await client.graphrag.query({
  query: "What were the main technical decisions this quarter?",
});

// Query across communities
const communityResults = await client.graphrag.queryCommunities({
  query: "infrastructure changes",
  limit: 5,
});

// Explain a specific memory's graph context
const explanation = await client.graphrag.explain({
  memoryId: "mem_abc123",
});

Search facts

const facts = await client.facts.search({
  query: "TypeScript",
  limit: 10,
});

for (const fact of facts.data) {
  console.log(`${fact.subject} → ${fact.predicate} → ${fact.object}`);
}

Search conversations

const conversations = await client.conversations.search({
  query: "authentication implementation",
  limit: 5,
});

Building a search interface

Here is a complete example of a search function with error handling:

import { MemnexusClient } from "@memnexus-ai/mx-typescript-sdk";

const client = new MemnexusClient({
  apiKey: process.env.MX_API_KEY,
});

async function search(query: string, options?: {
  topics?: string[];
  excludeTopics?: string[];
  recent?: string;
  limit?: number;
}) {
  try {
    const results = await client.memories.search({
      query,
      topics: options?.topics,
      excludeTopics: options?.excludeTopics,
      recent: options?.recent,
      limit: options?.limit ?? 10,
    });

    return results.data.map((result) => ({
      id: result.memory.id,
      content: result.memory.content,
      score: result.score,
      topics: result.memory.topics,
    }));
  } catch (error) {
    if (error.status === 401) {
      throw new Error("Invalid API key");
    }
    throw error;
  }
}

// Usage
const results = await search("deployment issues", {
  topics: ["core-api"],
  recent: "7d",
});

Next steps