LlamaIndex
llama-index-memory-gnarl gives a LlamaIndex agent a memory that lives on the
user's own node: a memory block for the Memory API, and a retriever.
They are thin wrappers over the Python client; the
node embeds, so there is no embedding model to configure.
pip install llama-index-memory-gnarl
With the Gnarly app running there is no address to configure: the client finds
the node through $GNARL_URL, then the endpoint the node on this machine
recorded, then http://127.0.0.1:43300.
from llama_index.core.memory import Memory
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.memory.gnarl import GnarlMemoryBlock
block = GnarlMemoryBlock(namespace="agent-memory", user="alice")
await block.aremember("Alice is vegetarian") # store a fact directly
memory = Memory.from_defaults(session_id="thread-42", memory_blocks=[block])
agent = FunctionAgent(llm=llm, tools=[])
await agent.run("Suggest a dinner for me", memory=memory) # recalls "vegetarian"
GnarlMemoryBlock
GnarlMemoryBlock(client=None, namespace=None, space=None, user=None, session=None, k=5,
min_score=None, retrieval_context_window=1, store_roles=[USER, ASSISTANT],
require_complete=False, name="GnarlMemory", priority=0)
- get recalls the
kmemories most relevant to the latestretrieval_context_windowmessages and returns them as- …lines, whichMemoryplaces in its memory-blocks template. - put receives the messages
Memoryflushes out of short-term history when its token limit is reached. Each user and assistant message is stored as one memory with itssession. To store every turn immediately, callblock.aput(messages)yourself, oraremember(text)for a single fact. - Recall is scoped to
userby the node, and spans all sessions unlesssessionis set. - If part of the memory did not answer, the text ends with a note saying
memories may be missing;
require_complete=TrueraisesIncompleteRecall.
GnarlRetriever
GnarlRetriever(client=None, *, async_client=None, namespace=None, space=None, user=None,
session=None, k=4, require_complete=False)
A BaseRetriever returning NodeWithScores whose metadata carries score,
knn_score, fact_type, session, agent, created, tags, namespace,
partial and coverage. Use it anywhere LlamaIndex takes a retriever, for
example RetrieverQueryEngine.from_args(GnarlRetriever(user="alice")).
Source
llama-index-memory-gnarl on GitHub · Apache-2.0