Skip to main content

The framework for agent memory

Project description

simplememory

This will be the memory of the agents and agency

To use this package:

Ensure that a .env exists with below parameters.

OPENAI_API_KEY=sk-"ADD YOUR API KEY HERE"
PINECONE_API_KEY = "ADD YOUR API KEY HERE"
PINECONE_INDEX="ADD YOUR INDEX NAME HERE"

If using entity memory or v1 of semantic memory, below parameters are needed

OPENAI_API_KEY = "ADD YOUR API KEY HERE"
NEO4J_URI = "ADD YOUR NEO4J URI HERE"
NEO4J_USERNAME = "ADD YOUR NEO4J USERNAME HERE"
NEO4J_PASSWORD = "ADD YOUR NEO4J PASSWORD"

How to add to semantic memory:

  • use v1 of semantic memory which uses NEO4J
# Below version will be deprecated use v1
from memory.semantic_memory import SemanticMemory
if __name__=="__main__":
    sc= SemanticMemory()
    semantic_val,memory_item = sc.add_memory_item(mem_key="What is the capital of india?",mem_val="The capital of India is New Delhi"
    print(semantic_val)
    print(memory_item)

# V1 of semantic memory
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_openai import ChatOpenAI
from memory.v1.semantic_memory_v1 import SemanticMemory

if __name__ == "__main__":
    llm = ChatOpenAI()
    sm = SemanticMemory()
    generation_prompt = ChatPromptTemplate.from_messages([
        (
            "system",
            "You will answer based on a question asked.",
        ),
        MessagesPlaceholder(variable_name="messages"), ])
    generate = generation_prompt | ChatOpenAI()
    while True:
        user_input = input("User: ")
        messages = generate.invoke({"messages": [user_input]})
        sm.add_memory_item(mem_key=user_input,
            mem_val=messages.content)

How to retrieve semantic memory:

  • use V1 of sematic memory. It uses NEO4J.
# The below will be deprecated
from memory.semantic_memory import SemanticMemory
if __name__=="__main__":
    sc= SemanticMemory()
    result = sc.retrieve_memory_item(mem_key="what is the capital of India?")
    print(result['matches'][0]['metadata']['key'])
    print(result['matches'][0]['metadata']['value'])
    print(result['matches'][0]['score'])
from memory.v1.semantic_memory_v1 import SemanticMemory

sm = SemanticMemory()
question = "What is blockchain?"
memory = sm.retrieve_memory_item(mem_key=question)
memory_key = memory[0]['name']
print(memory[0]['name'])
memory_value = sm.retrieve_memory_value(memory_key)
print(memory_value)

How to add entity memory:

from memory.entity_memory import EntityMemory

if __name__=="__main__":
    sc= EntityMemory()
    sc.add_memory_item(mem_key="What is the capital of India?",mem_val="The capital of India is New Delhi")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplememory-0.0.3.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplememory-0.0.3-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file simplememory-0.0.3.tar.gz.

File metadata

  • Download URL: simplememory-0.0.3.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.7

File hashes

Hashes for simplememory-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5a67fc6d265441750b0569494bc53545d25957f17d8750c0de9316568562871f
MD5 0d3459fb5e65e6e9c7bd4563a5595df3
BLAKE2b-256 61a876cf0cbd2b095ec930400445ce54381e5c11d7a5c5ed2bcbe76848e95889

See more details on using hashes here.

File details

Details for the file simplememory-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: simplememory-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.7

File hashes

Hashes for simplememory-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 271325eacd3364ee6e5e6ed012b4ab2a0c5ba0e738746e8b2c77537a55097c22
MD5 813c35bd90b73e6578ad875f0ded9b14
BLAKE2b-256 6faaa087ee16c09d7af962d3922a481220b334c64d9819063464e9d0d519d7dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page