RetrievalMem

RetrievalMem#

Overview#

RetrievalMem is a memory function provided by the Agent framework, which can be directly connected to Agent nodes and used as a RAG function.

Characteristics#

  • As a memory module: RetrievalMem inherits from MemBase, is a memory module that can be integrated into the Agent system

  • RAG Function: RetrievalMem essentially implements the RAG function, and RAG can be directly implemented based on RetrievalMem

  • Memory Storage: The memory content in RetrievalMem will not be refreshed based on context during the Agent’s execution process, but requires the user to pass a list of texts through the add_texts method, such as a list of document slices.

Best Practices#

Build a RAG module containing Retrival and Rerank based on RetrievalMem

from evofabric.core.vectorstore import ChromaDB
from evofabric.core.mem import RetrievalMem
from evofabric.core.clients import OpenAIEmbedClient, FlagRerankModel, RerankClientBase

embed_client = OpenAIEmbedClient(
        api_key="your-api-key",
        base_url="your-base-url",
        model="qwen3_0.6B:latest",
    )


vectorstore = ChromaDB(
    collection_name="chroma_db",
    persist_directory="./chroma_test",
    embedding=embed_client,
)

rerank_model = FlagRerankModel(
    model="your-model-path",
    top_n=3,
    devices="cpu"
)

retrieval_mem = RetrievalMem(
    vectorstore=vectorstore,
    reranker=rerank_model,
    use_rerank=True
)

await retrieval_mem.clear()
await retrieval_mem.add_texts(["The Tianjin Sports Games will open on May 26, 2024."])
await retrieval_mem.add_texts(["The Jinan Sports Games will open on June 26, 2024."])
await retrieval_mem.add_texts(["The Changsha Sports Games will open on July 26, 2024."])
# You can also add all texts together.

result_messages = await retrieval_mem.retrieval_update([UserMessage(content="What's the date of Tianjin Sports Games")])