Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.memvid.com/llms.txt

Use this file to discover all available pages before exploring further.

Integrate Memvid with LlamaIndex to build powerful RAG applications. The llamaindex adapter provides native LlamaIndex components for seamless integration.

Installation

npm install @memvid/sdk llamaindex @llamaindex/openai

Quick Start

import { use } from '@memvid/sdk';

// Open with LlamaIndex adapter
const mem = await use('llamaindex', 'knowledge.mv2');

// Access LlamaIndex tools
const tools = mem.tools;       // FunctionTool array
const functions = mem.functions; // Raw function schemas

// Use query engine
const queryEngine = mem.asQueryEngine();
const response = await queryEngine.query({ query: 'What is Memvid?' });
console.log(response.response);

Available Tools

The LlamaIndex adapter provides three tools:
ToolDescription
memvid_putStore documents in memory with title, label, and text
memvid_findSearch for relevant documents by query
memvid_askAsk questions with RAG-style answer synthesis

Using with Agents

import { use } from '@memvid/sdk';

// Get Memvid tools
const mem = await use('llamaindex', 'knowledge.mv2');
const tools = mem.tools;

// Tools can be used directly
for (const tool of tools) {
  console.log(`Tool: ${tool.metadata.name}`);
  console.log(`Description: ${tool.metadata.description}`);
}

// Or use with LlamaIndex agents (when available)
// Note: LlamaIndex.TS agent API is evolving

Using as a Query Engine

import { use } from '@memvid/sdk';

// Initialize
const mem = await use('llamaindex', 'knowledge.mv2');

// Get query engine factory
const queryEngine = mem.asQueryEngine();

// Query
const response = await queryEngine.query({ query: 'What is Memvid?' });
console.log(`Answer: ${response.response}`);

// Access sources
if (response.sourceNodes) {
  for (const node of response.sourceNodes) {
    console.log(`Source: ${node.node.metadata?.title}`);
  }
}

Using as a Vector Store (Python)

from memvid_sdk import use
from llama_index.core import VectorStoreIndex
from llama_index.llms.openai import OpenAI

# Initialize with llamaindex adapter
mem = use('llamaindex', 'knowledge.mv2', read_only=True)

# Get the vector store
vector_store = mem.as_vector_store()

# Build index from vector store
index = VectorStoreIndex.from_vector_store(vector_store)

# Create query engine
query_engine = index.as_query_engine(
    llm=OpenAI(model="gpt-4o")
)

# Query
response = query_engine.query("Explain the architecture")
print(response)

Chat Engine (Python)

from memvid_sdk import use
from llama_index.core import VectorStoreIndex
from llama_index.core.memory import ChatMemoryBuffer
from llama_index.llms.openai import OpenAI

# Initialize
mem = use('llamaindex', 'knowledge.mv2', read_only=True)
vector_store = mem.as_vector_store()

# Build index
index = VectorStoreIndex.from_vector_store(vector_store)

# Create chat engine with memory
chat_engine = index.as_chat_engine(
    chat_mode="context",
    llm=OpenAI(model="gpt-4o"),
    memory=ChatMemoryBuffer.from_defaults(token_limit=3000)
)

# Chat
response = chat_engine.chat("What is Memvid?")
print(response)

# Follow-up (maintains context)
response = chat_engine.chat("How does search work?")
print(response)

Custom Search Options

from memvid_sdk import use

mem = use('llamaindex', 'knowledge.mv2')

# Search with specific mode
results = mem.find('authentication', mode='lex', k=10)  # Lexical only
results = mem.find('user login flow', mode='sem', k=10)  # Semantic only
results = mem.find('auth best practices', mode='auto', k=10)  # Hybrid

# With scope filtering
results = mem.find('API', scope='mv2://docs/', k=5)

Best Practices

  1. Use read-only mode for retrieval-only applications
  2. Set appropriate k values based on your context window
  3. Use hybrid mode for best recall
  4. Close the memory when done
mem = use('llamaindex', 'knowledge.mv2', read_only=True)
try:
    # Do work
    retriever = mem.as_retriever(k=10)
    # ... use retriever
finally:
    mem.seal()

Next Steps

LangChain

LangChain integration

Vercel AI SDK

Vercel AI SDK integration