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 response = await client.memories.searchMemories({
  query: "deployment issues",
  limit: 10,
});

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

This runs a hybrid search by default. The query is embedded, 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 response = await client.memories.searchMemories({
  query: "authentication",
  topics: ["implementation", "completed"],
  limit: 10,
});

Choose a search method

Override the default hybrid pipeline with searchMethod:

const response = await client.memories.searchMemories({
  query: "debugging",
  searchMethod: "semantic", // "keyword" | "semantic" | "hybrid"
  limit: 10,
});

Time-based filtering

Filter by when the system ingested a memory using ISO 8601 timestamps:

const response = await client.memories.searchMemories({
  query: "deployments",
  ingestionTimeFrom: "2026-06-25T00:00:00Z",
  ingestionTimeTo: "2026-07-03T00:00:00Z",
  limit: 10,
});

GraphRAG queries

For complex queries that benefit from traversing the knowledge graph:

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

Search facts

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

for (const fact of response.data?.data ?? []) {
  console.log(`${fact.subject} → ${fact.predicate} → ${fact.object}`);
}

Search conversations

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

Building a search interface

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

import { Memnexus, SdkError } from "@memnexus-ai/typescript-sdk";

const client = new Memnexus({
  token: process.env.MX_API_KEY,
});

async function search(query: string, options?: {
  topics?: string[];
  searchMethod?: "keyword" | "semantic" | "hybrid";
  limit?: number;
}) {
  try {
    const response = await client.memories.searchMemories({
      query,
      topics: options?.topics,
      searchMethod: options?.searchMethod,
      limit: options?.limit ?? 10,
    });

    return (response.data?.data ?? []).map((result) => ({
      id: result.memory.id,
      content: result.memory.content,
      score: result.score,
      topics: result.memory.topics,
    }));
  } catch (error) {
    if (error instanceof SdkError && error.status === 401) {
      throw new Error("Invalid API key");
    }
    throw error;
  }
}

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

Next steps