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_smart_readRead all memory into a bounded context block
memory_searchBM25 full-text search over memory
memory_memorizeFeed raw text and let MemexAI decide what to write

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

On this page