Adapters

LlamaIndex

Use MemexAI memory tools with LlamaIndex in Python.

The LlamaIndex adapter wraps all seven MemexAI memory tools as FunctionTool objects for use with any LlamaIndex agent.

Before you start

Install

pip install memexai llama-index-core

Usage

from memexai import MemexAI
from memexai.adapters.llamaindex import get_llamaindex_tools
from llama_index.core.agent import FunctionCallingAgentWorker
from llama_index.llms.google import Gemini

memex = MemexAI(url="http://localhost:8080", api_key="dev-agent-key")
user = memex.for_user("user_123", actor="assistant")
tools = get_llamaindex_tools(user)

llm = Gemini(model="models/gemini-2.5-flash")
worker = FunctionCallingAgentWorker.from_tools(tools, llm=llm, verbose=True)
agent = worker.as_agent()

response = await agent.achat("Remember that I prefer quiet neighborhoods near good schools.")
print(response)

await memex.close()

Available tools

get_llamaindex_tools returns seven FunctionTool objects:

ToolPurpose
memory_listList files visible to the current user
memory_readRead a single file by virtual path
memory_writeCreate or overwrite a user file
memory_patchApply targeted updates (append, replace)
memory_findBM25 or hybrid pgvector search with RRF fusion over memory
memory_rememberFeed raw text and let MemexAI decide what to write
memory_contextAssemble retrieval context using memory_find, memory_read, and memory_list internally

This example exposes all tools so you can see the full adapter shape. For most assistants, passing only memory_remember and memory_context is enough. Include the full set when the agent needs direct file control.

Examples

Working Python examples with hot path and background path patterns:

On this page