Skip to main content

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 k memories most relevant to the latest retrieval_context_window messages and returns them as - … lines, which Memory places in its memory-blocks template.
  • put receives the messages Memory flushes out of short-term history when its token limit is reached. Each user and assistant message is stored as one memory with its session. To store every turn immediately, call block.aput(messages) yourself, or aremember(text) for a single fact.
  • Recall is scoped to user by the node, and spans all sessions unless session is set.
  • If part of the memory did not answer, the text ends with a note saying memories may be missing; require_complete=True raises IncompleteRecall.

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