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
- Run the containerized service or another MemexAI service endpoint.
- Read How MemexAI works for the tool-call-to-Postgres flow.
- Read Memory tools to choose the memory subagent or the full raw file tool set.
- Read Memory scopes before writing paths like
user/profile.md.
Install
pip install memexai llama-index-coreUsage
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:
| Tool | Purpose |
|---|---|
memory_list | List files visible to the current user |
memory_read | Read a single file by virtual path |
memory_write | Create or overwrite a user file |
memory_patch | Apply targeted updates (append, replace) |
memory_find | BM25 or hybrid pgvector search with RRF fusion over memory |
memory_remember | Feed raw text and let MemexAI decide what to write |
memory_context | Assemble 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: