Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
83d1576
fix bugs: try to fix bugs in _submit_web_logs
tangg555 Dec 18, 2025
e50c56c
fix bugs: try to address bugs
tangg555 Dec 18, 2025
74f1da0
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Dec 18, 2025
58eb6b8
fix bugs
tangg555 Dec 18, 2025
392b6df
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Dec 18, 2025
0d72ce7
refactor: modify examples
tangg555 Dec 18, 2025
2fe965b
revise add operation and fix an unbelievable bug
tangg555 Dec 18, 2025
26267f4
Merge branch 'dev' into scheduler
tangg555 Dec 18, 2025
eecfa51
address the bug issues
tangg555 Dec 22, 2025
7c6b7da
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Dec 22, 2025
f2da3a7
the doc file has a format problem which has been fixed in this commit
tangg555 Dec 24, 2025
a6881b4
add a range of new feats for the add operation
tangg555 Dec 24, 2025
7f39e7e
address the incompatible issue of local scheduler
tangg555 Dec 24, 2025
6778cc4
address the conflicts
tangg555 Dec 24, 2025
3fe9cb0
feat(scheduler): optimize redis queue consumer group management
tangg555 Dec 24, 2025
b35096f
fix(tests): resolve AttributeError in SimpleStructMemReader tests
tangg555 Dec 24, 2025
a7f5b77
Merge branch 'dev' into dev
tangg555 Dec 24, 2025
ded7ac6
Merge branch 'dev' into dev
tangg555 Dec 24, 2025
8943ba8
fix(mem_reader): pass info dict to add_before_search for correct user…
tangg555 Dec 24, 2025
78a4327
refactor add_before_search from mem_reader to SingleCubeView
tangg555 Dec 24, 2025
a5fc4c0
address bugs
tangg555 Dec 24, 2025
45224dd
fix: fix the qsize bug of task queue, and accept change from hotfix/s…
tangg555 Dec 25, 2025
f3c4f6c
fix: address some issues to run old scheduler example and kv cache ex…
tangg555 Dec 26, 2025
d634851
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Dec 26, 2025
e9b60db
fix: address the issue of Top-level import of unavailable module 'torch'
tangg555 Dec 26, 2025
c6bdb22
fix: resolve linting errors and make optional dependencies lazy loaded
tangg555 Dec 26, 2025
077f529
Merge branch 'dev' into scheduler
tangg555 Dec 29, 2025
5abbe23
Merge branch 'dev' into scheduler
tangg555 Dec 29, 2025
ad3620a
refactor: revise the rewrite prompt to make it better
tangg555 Dec 29, 2025
2475286
refactor: update examples
tangg555 Dec 30, 2025
24c9b18
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Dec 30, 2025
0ecee35
Merge branch 'dev' into scheduler
tangg555 Dec 30, 2025
a196dcb
refactor: update examples for scheduler
tangg555 Dec 30, 2025
af39bfc
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Dec 30, 2025
6139af8
fix bugs: address the unsupported xautoclaim command when redis versi…
tangg555 Jan 6, 2026
686d7c1
refactor: review settings
tangg555 Jan 7, 2026
3dd5068
refactor: adjust examples to make it run better for code debugging
tangg555 Jan 7, 2026
211b4dc
refactor: review slow add apis to get a better performance on Halumen
tangg555 Jan 7, 2026
f0a9c13
fix bugs: address the issue when set user_redis_queue to false, the s…
tangg555 Jan 7, 2026
079a3e3
refactor: allow the code to run without rabbitmq
tangg555 Jan 8, 2026
e01863d
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Jan 8, 2026
3a75d3a
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Jan 8, 2026
d2e6c68
refactor: create a _parse_pending_entry for redis queue
tangg555 Jan 8, 2026
412b05a
refactor: add a try/catch for status_tracker
tangg555 Jan 8, 2026
55dc088
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Jan 8, 2026
5534709
Merge remote-tracking branch 'upstream/dev' into dev
tangg555 Jan 9, 2026
1f1a81d
fix: revise examples of textual memories to run normally
tangg555 Jan 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 47 additions & 14 deletions examples/core_memories/general_textual_memory.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import os
import pprint

from memos.configs.memory import MemoryConfigFactory
from memos.memories.factory import MemoryFactory


# Initialize the memory configuration
# This configuration specifies the extractor, vector database, and embedder backend.
# Here we use OpenAI for extraction, Qdrant for vector storage, and Ollama for embedding.
config = MemoryConfigFactory(
backend="general_text",
config={
"extractor_llm": {
"backend": "ollama",
"backend": "openai",
"config": {
"model_name_or_path": "qwen3:0.6b",
"model_name_or_path": "gpt-4o-mini",
"api_key": os.environ.get("OPENAI_API_KEY"),
"api_base": os.environ.get(
"OPENAI_BASE_URL",
os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
),
"temperature": 0.0,
"remove_think_prefix": True,
"max_tokens": 8192,
Expand All @@ -30,6 +41,8 @@
},
},
)

# Create the memory instance from the configuration
m = MemoryFactory.from_config(config)

example_memories = [
Expand All @@ -52,20 +65,25 @@
},
},
]

example_id = "a19b6caa-5d59-42ad-8c8a-e4f7118435b4"

print("===== Extract memories =====")
# Extract memories from a conversation
# The extractor LLM processes the conversation to identify relevant information.
memories = m.extract(
[
{"role": "user", "content": "I love tomatoes."},
{"role": "assistant", "content": "Great! Tomatoes are delicious."},
]
)
print(memories)
pprint.pprint(memories)
print()

print("==== Add memories ====")
# Add the extracted memories to the memory store
m.add(memories)
# Add a manually created memory item
m.add(
[
{
Expand All @@ -80,19 +98,27 @@
}
]
)
print(m.get_all())
print("All memories after addition:")
pprint.pprint(m.get_all())
print()

print("==== Search memories ====")
# Search for memories related to a query
search_results = m.search("Tell me more about the user", top_k=2)
print(search_results)
pprint.pprint(search_results)
print()

print("==== Get memories ====")
print(m.get(example_id))
print(m.get_by_ids([example_id]))
# Retrieve a specific memory by its ID
print(f"Memory with ID {example_id}:")
pprint.pprint(m.get(example_id))
# Retrieve multiple memories by IDs
print(f"Memories by IDs [{example_id}]:")
pprint.pprint(m.get_by_ids([example_id]))
print()

print("==== Update memories ====")
# Update an existing memory
m.update(
example_id,
{
Expand All @@ -106,19 +132,26 @@
},
},
)
print(m.get(example_id))
print(f"Memory after update (ID {example_id}):")
pprint.pprint(m.get(example_id))
print()

print("==== Dump memory ====")
# Dump the current state of memory to a file
m.dump("tmp/general_mem")
print("Memory dumped to 'tmp/general_mem'.")
print()

print("==== Delete memories ====")
# Delete a memory by its ID
m.delete([example_id])
print(m.get_all())
print("All memories after deletion:")
pprint.pprint(m.get_all())
print()

print("==== Delete all memories ====")
# Clear all memories from the store
m.delete_all()
print(m.get_all())
print("All memories after delete_all:")
pprint.pprint(m.get_all())
print()

print("==== Dump memory ====")
m.dump("tmp/mem")
print("Memory dumped to 'tmp/mem'.")
79 changes: 55 additions & 24 deletions examples/core_memories/naive_textual_memory.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,77 @@
import json
import os
import uuid

from memos.configs.memory import MemoryConfigFactory
from memos.memories.factory import MemoryFactory


def print_result(title, result):
"""Helper function: Pretty print the result."""
print(f"\n{'=' * 10} {title} {'=' * 10}")
if isinstance(result, list | dict):
print(json.dumps(result, indent=2, ensure_ascii=False, default=str))
else:
print(result)


# Configure memory backend with OpenAI extractor
config = MemoryConfigFactory(
backend="naive_text",
config={
"extractor_llm": {
"backend": "ollama",
"backend": "openai",
"config": {
"model_name_or_path": "qwen3:0.6b",
"model_name_or_path": "gpt-4o-mini",
"api_key": os.environ.get("OPENAI_API_KEY"),
"api_base": os.environ.get(
"OPENAI_BASE_URL",
os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
),
"temperature": 0.0,
"remove_think_prefix": True,
},
}
},
)

# Create memory instance
m = MemoryFactory.from_config(config)


print("===== Extract memories =====")
# Extract memories from a simulated conversation
memories = m.extract(
[
{"role": "user", "content": "I love tomatoes."},
{"role": "assistant", "content": "Great! Tomatoes are delicious."},
]
)
print(memories)
print()
print_result("Extract memories", memories)


print("==== Add memories ====")
# Add the extracted memories to storage
m.add(memories)

# Manually create a memory item and add it
example_id = str(uuid.uuid4())
m.add([{"id": example_id, "memory": "User is Chinese.", "metadata": {"type": "opinion"}}])
print(m.get_all())
print()
manual_memory = [{"id": example_id, "memory": "User is Chinese.", "metadata": {"type": "opinion"}}]
m.add(manual_memory)

# Print all current memories
print_result("Add memories (Check all after adding)", m.get_all())

print("==== Search memories ====")

# Search for relevant memories based on the query
search_results = m.search("Tell me more about the user", top_k=2)
print(search_results)
print()
print_result("Search memories", search_results)


# Get specific memory item by ID
memory_item = m.get(example_id)
print_result("Get memory", memory_item)

print("==== Get memories ====")
memories = m.get(example_id)
print(memories)
print()

print("==== Update memories ====")
# Update the memory content for the specified ID
m.update(
example_id,
{
Expand All @@ -56,15 +80,22 @@
"metadata": {"type": "opinion", "confidence": 85},
},
)
print(m.get(example_id))
updated_memory = m.get(example_id)
print_result("Update memory", updated_memory)


print("==== Dump memory ====")
# Dump the current state of memory to a file
m.dump("tmp/naive_mem")
print("Memory dumped to 'tmp/naive_mem'.")
print()

print("==== Delete memories ====")

# Delete memory with the specified ID
m.delete([example_id])
print(m.get_all())
print()
print_result("Delete memory (Check all after deleting)", m.get_all())

print("==== Delete all memories ====")

# Delete all memories in storage
m.delete_all()
print(m.get_all())
print()
print_result("Delete all", m.get_all())