Skip to main content

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")

Metadata

Release files for simplememory 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simplememory 0.0.3
File Size Uploaded
simplememory-0.0.3.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simplememory 0.0.3
File Interpreter ABI Platform
simplememory-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / simplememory-0.0.3.tar.gz

Download URL simplememory-0.0.3.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5a67fc6d265441750b0569494bc53545d25957f17d8750c0de9316568562871f
BLAKE2b-256 checksum
How to use checksums
61a876cf0cbd2b095ec930400445ce54381e5c11d7a5c5ed2bcbe76848e95889
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.7

Release files / simplememory-0.0.3-py3-none-any.whl

Download URL simplememory-0.0.3-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
271325eacd3364ee6e5e6ed012b4ab2a0c5ba0e738746e8b2c77537a55097c22
BLAKE2b-256 checksum
How to use checksums
6faaa087ee16c09d7af962d3922a481220b334c64d9819063464e9d0d519d7dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page