Skip to content

[Question]: 可否给出一个类似mem0用法的示例 #1202

@l2002924700

Description

@l2002924700

Your Question

您好,我是在进行openViking对接autogen,因为autogen实现了mem0系统的接入,所以参考mem0在autogen中的实现,需要使用openviking实现类似的接口。我把openviking的文档从头看到尾,没有找到类似的实现。所以想请你们给出一个类似如下mem0代码实现功能的openviking的实现。

from autogen_ext.memory.mem0 import Mem0Memory
from mem0 import Memory as Memory0
from mem0 import MemoryClient
client = Memory0.from_config(
        {
            "history_db_path": ":memory:",
            "embedder": {
                "provider": "ollama",
                "config": {"model": "qwen2.5:7b", "ollama_base_url": "http://localhost:11434"}
            },
            "llm": {
    #        "provider": "mock_llm",
                "provider": "ollama",
                "config": {
                    "model": "qwen2.5:7b",
                    #"temperature": 0.2,
                    #"max_tokens": 2048,
                    "ollama_base_url": "http://localhost:11434"
                }

            },  # Use in-memory storage for testing
            "vector_store": {
                "provider": "chroma",
                "config": {"collection_name": "test", "path": ":memory:"}
            }
        }
    )
print("Memory initialized successfully!")
# Add something to memory
message = "User likes the color blue."
user_id="alice"
client.add([{"role": "user", "content": message}], user_id=user_id)
query_text = "What color does the user like?"
results = client.search(  # type: ignore
                    query_text,
                    user_id="alice",
                    limit=5,
                )
print(f"mem0 search results:: {results}")

上面代码的输出如下:

mem0 search results:: {'results': [{'id': 'b77eee85-0246-4819-8f06-3c6da2e8e0ed', 'memory': 'Likes the color blue', 'hash': 'e5db483c46c111dbe776a0c23d898b48', 'metadata': None, 'score': 99409.875, 'created_at': '2026-04-02T23:45:16.512058-07:00', 'updated_at': None, 'user_id': 'alice'}]}

Context

谢谢你们

Code Example (Optional)

Related Area

None

Before Asking

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions