hy-memory 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hy_memory-1.0.0/LICENSE +21 -0
- hy_memory-1.0.0/PKG-INFO +136 -0
- hy_memory-1.0.0/README.md +92 -0
- hy_memory-1.0.0/hy_memory/__init__.py +146 -0
- hy_memory-1.0.0/hy_memory/agent/__init__.py +99 -0
- hy_memory-1.0.0/hy_memory/agent/abstractor.py +300 -0
- hy_memory-1.0.0/hy_memory/agent/emotion_analyzer.py +284 -0
- hy_memory-1.0.0/hy_memory/agent/extractor.py +558 -0
- hy_memory-1.0.0/hy_memory/agent/intention_detector.py +328 -0
- hy_memory-1.0.0/hy_memory/agent/llm_provider.py +606 -0
- hy_memory-1.0.0/hy_memory/agent/mem_agent.py +377 -0
- hy_memory-1.0.0/hy_memory/agent/prompts_zh.py +316 -0
- hy_memory-1.0.0/hy_memory/agent/reconciler.py +999 -0
- hy_memory-1.0.0/hy_memory/agent/reflector.py +480 -0
- hy_memory-1.0.0/hy_memory/agent/summarizer.py +169 -0
- hy_memory-1.0.0/hy_memory/agent/tools/__init__.py +43 -0
- hy_memory-1.0.0/hy_memory/agent/tools/base.py +237 -0
- hy_memory-1.0.0/hy_memory/agent/tools/basic_profile.py +388 -0
- hy_memory-1.0.0/hy_memory/client.py +2238 -0
- hy_memory-1.0.0/hy_memory/config.py +675 -0
- hy_memory-1.0.0/hy_memory/core/__init__.py +20 -0
- hy_memory-1.0.0/hy_memory/core/embed_service.py +395 -0
- hy_memory-1.0.0/hy_memory/core/merger.py +324 -0
- hy_memory-1.0.0/hy_memory/core/scorer.py +254 -0
- hy_memory-1.0.0/hy_memory/data/__init__.py +50 -0
- hy_memory-1.0.0/hy_memory/data/cache.py +77 -0
- hy_memory-1.0.0/hy_memory/data/cache_base.py +285 -0
- hy_memory-1.0.0/hy_memory/data/cache_disabled.py +259 -0
- hy_memory-1.0.0/hy_memory/data/cache_memory.py +413 -0
- hy_memory-1.0.0/hy_memory/data/cache_redis.py +836 -0
- hy_memory-1.0.0/hy_memory/data/cache_sqlite.py +892 -0
- hy_memory-1.0.0/hy_memory/data/graph_store.py +57 -0
- hy_memory-1.0.0/hy_memory/data/graph_store_base.py +336 -0
- hy_memory-1.0.0/hy_memory/data/graph_store_kuzu.py +1374 -0
- hy_memory-1.0.0/hy_memory/data/graph_store_neo4j.py +1185 -0
- hy_memory-1.0.0/hy_memory/data/history_store.py +362 -0
- hy_memory-1.0.0/hy_memory/data/kv_store.py +357 -0
- hy_memory-1.0.0/hy_memory/data/rdb.py +193 -0
- hy_memory-1.0.0/hy_memory/data/storage_interface.py +432 -0
- hy_memory-1.0.0/hy_memory/data/vector_store.py +63 -0
- hy_memory-1.0.0/hy_memory/data/vector_store_base.py +374 -0
- hy_memory-1.0.0/hy_memory/data/vector_store_chroma.py +529 -0
- hy_memory-1.0.0/hy_memory/data/vector_store_faiss.py +553 -0
- hy_memory-1.0.0/hy_memory/data/vector_store_qdrant.py +837 -0
- hy_memory-1.0.0/hy_memory/inspector.py +445 -0
- hy_memory-1.0.0/hy_memory/models/__init__.py +178 -0
- hy_memory-1.0.0/hy_memory/models/memory.py +1213 -0
- hy_memory-1.0.0/hy_memory/models/requests.py +745 -0
- hy_memory-1.0.0/hy_memory/pipelines/__init__.py +49 -0
- hy_memory-1.0.0/hy_memory/pipelines/_retrieval/__init__.py +15 -0
- hy_memory-1.0.0/hy_memory/pipelines/_retrieval/bm25.py +115 -0
- hy_memory-1.0.0/hy_memory/pipelines/_retrieval/config.py +133 -0
- hy_memory-1.0.0/hy_memory/pipelines/_retrieval/evolution.py +242 -0
- hy_memory-1.0.0/hy_memory/pipelines/_retrieval/intent.py +155 -0
- hy_memory-1.0.0/hy_memory/pipelines/_retrieval/rrf.py +94 -0
- hy_memory-1.0.0/hy_memory/pipelines/_retrieval/tag_index.py +199 -0
- hy_memory-1.0.0/hy_memory/pipelines/_retrieval/trace.py +639 -0
- hy_memory-1.0.0/hy_memory/pipelines/base.py +373 -0
- hy_memory-1.0.0/hy_memory/pipelines/cross_domain_sweeper.py +679 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/_retrieval/__init__.py +15 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/_retrieval/bm25.py +115 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/_retrieval/config.py +132 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/_retrieval/evolution.py +242 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/_retrieval/intent.py +155 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/_retrieval/rrf.py +94 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/_retrieval/tag_index.py +199 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/_retrieval/trace.py +484 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/reader_hybrid.py +574 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/reader_hybrid_tag.py +467 -0
- hy_memory-1.0.0/hy_memory/pipelines/lite/reader_legacy.py +498 -0
- hy_memory-1.0.0/hy_memory/pipelines/reader.py +112 -0
- hy_memory-1.0.0/hy_memory/pipelines/reader_exhaustive.py +620 -0
- hy_memory-1.0.0/hy_memory/pipelines/reader_hybrid.py +574 -0
- hy_memory-1.0.0/hy_memory/pipelines/reader_hybrid_tag.py +467 -0
- hy_memory-1.0.0/hy_memory/pipelines/reader_legacy.py +793 -0
- hy_memory-1.0.0/hy_memory/pipelines/registry.py +190 -0
- hy_memory-1.0.0/hy_memory/pipelines/system2_agent.py +801 -0
- hy_memory-1.0.0/hy_memory/pipelines/system2_tools.py +466 -0
- hy_memory-1.0.0/hy_memory/pipelines/system2_writer.py +697 -0
- hy_memory-1.0.0/hy_memory/pipelines/writer.py +1057 -0
- hy_memory-1.0.0/hy_memory/server.py +375 -0
- hy_memory-1.0.0/hy_memory/utils/lang_detect.py +165 -0
- hy_memory-1.0.0/hy_memory/utils/log_setup.py +170 -0
- hy_memory-1.0.0/hy_memory/utils/metrics.py +270 -0
- hy_memory-1.0.0/hy_memory/utils/time_window.py +169 -0
- hy_memory-1.0.0/hy_memory/utils/tracer.py +381 -0
- hy_memory-1.0.0/hy_memory.egg-info/PKG-INFO +136 -0
- hy_memory-1.0.0/hy_memory.egg-info/SOURCES.txt +101 -0
- hy_memory-1.0.0/hy_memory.egg-info/dependency_links.txt +1 -0
- hy_memory-1.0.0/hy_memory.egg-info/requires.txt +41 -0
- hy_memory-1.0.0/hy_memory.egg-info/top_level.txt +1 -0
- hy_memory-1.0.0/pyproject.toml +70 -0
- hy_memory-1.0.0/setup.cfg +4 -0
- hy_memory-1.0.0/tests/test_cache_sqlite.py +514 -0
- hy_memory-1.0.0/tests/test_delete_by_metadata.py +374 -0
- hy_memory-1.0.0/tests/test_log_quality.py +258 -0
- hy_memory-1.0.0/tests/test_models.py +472 -0
- hy_memory-1.0.0/tests/test_retrieval.py +205 -0
- hy_memory-1.0.0/tests/test_vector_search_adversarial.py +290 -0
- hy_memory-1.0.0/tests/test_vector_search_isolation.py +389 -0
- hy_memory-1.0.0/tests/test_vector_search_performance.py +315 -0
- hy_memory-1.0.0/tests/test_vector_search_sparse_user.py +316 -0
- hy_memory-1.0.0/tests/test_write_status.py +282 -0
hy_memory-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 HY Memory Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
hy_memory-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hy-memory
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: HY Memory - Intelligent hierarchical memory system for LLM agents
|
|
5
|
+
Author: alvinfei
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: pydantic
|
|
11
|
+
Requires-Dist: numpy
|
|
12
|
+
Requires-Dist: openai
|
|
13
|
+
Requires-Dist: python-dotenv
|
|
14
|
+
Requires-Dist: pyyaml
|
|
15
|
+
Requires-Dist: chromadb
|
|
16
|
+
Requires-Dist: langdetect
|
|
17
|
+
Provides-Extra: qdrant
|
|
18
|
+
Requires-Dist: qdrant-client; extra == "qdrant"
|
|
19
|
+
Provides-Extra: faiss
|
|
20
|
+
Requires-Dist: faiss-cpu; extra == "faiss"
|
|
21
|
+
Provides-Extra: graph
|
|
22
|
+
Requires-Dist: neo4j; extra == "graph"
|
|
23
|
+
Requires-Dist: kuzu; extra == "graph"
|
|
24
|
+
Provides-Extra: redis
|
|
25
|
+
Requires-Dist: redis; extra == "redis"
|
|
26
|
+
Provides-Extra: anthropic
|
|
27
|
+
Requires-Dist: anthropic; extra == "anthropic"
|
|
28
|
+
Provides-Extra: ml
|
|
29
|
+
Requires-Dist: scikit-learn; extra == "ml"
|
|
30
|
+
Provides-Extra: all
|
|
31
|
+
Requires-Dist: chromadb; extra == "all"
|
|
32
|
+
Requires-Dist: qdrant-client; extra == "all"
|
|
33
|
+
Requires-Dist: faiss-cpu; extra == "all"
|
|
34
|
+
Requires-Dist: kuzu; extra == "all"
|
|
35
|
+
Requires-Dist: neo4j; extra == "all"
|
|
36
|
+
Requires-Dist: redis; extra == "all"
|
|
37
|
+
Requires-Dist: anthropic; extra == "all"
|
|
38
|
+
Requires-Dist: scikit-learn; extra == "all"
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: pytest; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
42
|
+
Requires-Dist: httpx; extra == "dev"
|
|
43
|
+
Dynamic: license-file
|
|
44
|
+
|
|
45
|
+
# HY Memory
|
|
46
|
+
|
|
47
|
+
**Intelligent hierarchical memory system for LLM agents.**
|
|
48
|
+
|
|
49
|
+
HY Memory provides a production-grade memory layer for AI agents with LLM-driven extraction, semantic search, multi-layer knowledge representation, and graph-based schema inference.
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- **7-Layer Memory Architecture** — From raw facts (L1) to behavioral schemas (L6) and intentions (L7)
|
|
54
|
+
- **LLM-Driven Extraction** — Automatically extracts structured memories from conversations
|
|
55
|
+
- **Semantic Search** — Vector similarity search across all memory layers
|
|
56
|
+
- **Graph Knowledge** — Neo4j/Kuzu graph store for schema and intention inference (System 2)
|
|
57
|
+
- **Evolution Chains** — Tracks how memories evolve over time via supersedes links
|
|
58
|
+
- **Multiple Backends** — Qdrant, ChromaDB, FAISS for vectors; Neo4j, Kuzu for graphs
|
|
59
|
+
- **OpenAI-Compatible** — Works with any LLM that supports the OpenAI API format (DeepSeek, Qwen, Claude, etc.)
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install hy-memory
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from hy_memory import HyMemoryClient
|
|
69
|
+
|
|
70
|
+
client = HyMemoryClient(mode="lite")
|
|
71
|
+
|
|
72
|
+
# Write
|
|
73
|
+
client.add("I love sci-fi movies, especially Interstellar", user_id="user_1")
|
|
74
|
+
|
|
75
|
+
# Search
|
|
76
|
+
results = client.search("What movies does the user like?", user_id="user_1")
|
|
77
|
+
for mem in results["memories"]:
|
|
78
|
+
print(f" [{mem['score']:.2f}] {mem['content']}")
|
|
79
|
+
|
|
80
|
+
client.close()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
HY Memory is configured via environment variables. Minimal setup:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
export MEMORY_LLM_API_KEY="sk-your-key"
|
|
89
|
+
export MEMORY_LLM_BASE_URL="https://api.deepseek.com" # or any OpenAI-compatible endpoint
|
|
90
|
+
export MEMORY_LLM_MODEL="deepseek-chat"
|
|
91
|
+
|
|
92
|
+
export MEMORY_EMBEDDER_API_KEY="sk-your-key"
|
|
93
|
+
export MEMORY_EMBEDDER_BASE_URL="https://api.openai.com/v1"
|
|
94
|
+
export MEMORY_EMBEDDER_MODEL="text-embedding-3-small"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or copy `.env.example` and fill in your values:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
cp .env.example .env
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
See [docs/env_reference.md](docs/env_reference.md) for all available options.
|
|
104
|
+
|
|
105
|
+
## Modes
|
|
106
|
+
|
|
107
|
+
| Mode | Layers | Graph | Best For |
|
|
108
|
+
|------|--------|-------|----------|
|
|
109
|
+
| **lite** | L0-L4 (facts + identity) | No | Simple chatbots, quick setup |
|
|
110
|
+
| **pro** | L0-L5 (+ knowledge) | Optional | Knowledge-heavy applications |
|
|
111
|
+
| **ultra** | L0-L7 (+ schema + intention) | Yes | Full cognitive architecture |
|
|
112
|
+
|
|
113
|
+
## Vector Store Backends
|
|
114
|
+
|
|
115
|
+
| Backend | Install | Config |
|
|
116
|
+
|---------|---------|--------|
|
|
117
|
+
| **ChromaDB** (default) | included | `MEMORY_VECTOR_STORE=chroma` |
|
|
118
|
+
| **Qdrant** | `pip install hy-memory[qdrant]` | `MEMORY_VECTOR_STORE=qdrant` |
|
|
119
|
+
| **FAISS** | `pip install hy-memory[faiss]` | `MEMORY_VECTOR_STORE=faiss` |
|
|
120
|
+
|
|
121
|
+
## Graph Store Backends (Ultra mode)
|
|
122
|
+
|
|
123
|
+
| Backend | Install | Config |
|
|
124
|
+
|---------|---------|--------|
|
|
125
|
+
| **Kuzu** (default) | included | `MEMORY_GRAPH_PROVIDER=kuzu` |
|
|
126
|
+
| **Neo4j** | `pip install hy-memory[graph]` | `MEMORY_GRAPH_PROVIDER=neo4j` |
|
|
127
|
+
|
|
128
|
+
## Documentation
|
|
129
|
+
|
|
130
|
+
- [Usage Guide](docs/usage.md) — Detailed API documentation and examples
|
|
131
|
+
- [Environment Reference](docs/env_reference.md) — All configuration options
|
|
132
|
+
- [Contributing](CONTRIBUTING.md) — How to contribute
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# HY Memory
|
|
2
|
+
|
|
3
|
+
**Intelligent hierarchical memory system for LLM agents.**
|
|
4
|
+
|
|
5
|
+
HY Memory provides a production-grade memory layer for AI agents with LLM-driven extraction, semantic search, multi-layer knowledge representation, and graph-based schema inference.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **7-Layer Memory Architecture** — From raw facts (L1) to behavioral schemas (L6) and intentions (L7)
|
|
10
|
+
- **LLM-Driven Extraction** — Automatically extracts structured memories from conversations
|
|
11
|
+
- **Semantic Search** — Vector similarity search across all memory layers
|
|
12
|
+
- **Graph Knowledge** — Neo4j/Kuzu graph store for schema and intention inference (System 2)
|
|
13
|
+
- **Evolution Chains** — Tracks how memories evolve over time via supersedes links
|
|
14
|
+
- **Multiple Backends** — Qdrant, ChromaDB, FAISS for vectors; Neo4j, Kuzu for graphs
|
|
15
|
+
- **OpenAI-Compatible** — Works with any LLM that supports the OpenAI API format (DeepSeek, Qwen, Claude, etc.)
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install hy-memory
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from hy_memory import HyMemoryClient
|
|
25
|
+
|
|
26
|
+
client = HyMemoryClient(mode="lite")
|
|
27
|
+
|
|
28
|
+
# Write
|
|
29
|
+
client.add("I love sci-fi movies, especially Interstellar", user_id="user_1")
|
|
30
|
+
|
|
31
|
+
# Search
|
|
32
|
+
results = client.search("What movies does the user like?", user_id="user_1")
|
|
33
|
+
for mem in results["memories"]:
|
|
34
|
+
print(f" [{mem['score']:.2f}] {mem['content']}")
|
|
35
|
+
|
|
36
|
+
client.close()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
HY Memory is configured via environment variables. Minimal setup:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
export MEMORY_LLM_API_KEY="sk-your-key"
|
|
45
|
+
export MEMORY_LLM_BASE_URL="https://api.deepseek.com" # or any OpenAI-compatible endpoint
|
|
46
|
+
export MEMORY_LLM_MODEL="deepseek-chat"
|
|
47
|
+
|
|
48
|
+
export MEMORY_EMBEDDER_API_KEY="sk-your-key"
|
|
49
|
+
export MEMORY_EMBEDDER_BASE_URL="https://api.openai.com/v1"
|
|
50
|
+
export MEMORY_EMBEDDER_MODEL="text-embedding-3-small"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or copy `.env.example` and fill in your values:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
cp .env.example .env
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
See [docs/env_reference.md](docs/env_reference.md) for all available options.
|
|
60
|
+
|
|
61
|
+
## Modes
|
|
62
|
+
|
|
63
|
+
| Mode | Layers | Graph | Best For |
|
|
64
|
+
|------|--------|-------|----------|
|
|
65
|
+
| **lite** | L0-L4 (facts + identity) | No | Simple chatbots, quick setup |
|
|
66
|
+
| **pro** | L0-L5 (+ knowledge) | Optional | Knowledge-heavy applications |
|
|
67
|
+
| **ultra** | L0-L7 (+ schema + intention) | Yes | Full cognitive architecture |
|
|
68
|
+
|
|
69
|
+
## Vector Store Backends
|
|
70
|
+
|
|
71
|
+
| Backend | Install | Config |
|
|
72
|
+
|---------|---------|--------|
|
|
73
|
+
| **ChromaDB** (default) | included | `MEMORY_VECTOR_STORE=chroma` |
|
|
74
|
+
| **Qdrant** | `pip install hy-memory[qdrant]` | `MEMORY_VECTOR_STORE=qdrant` |
|
|
75
|
+
| **FAISS** | `pip install hy-memory[faiss]` | `MEMORY_VECTOR_STORE=faiss` |
|
|
76
|
+
|
|
77
|
+
## Graph Store Backends (Ultra mode)
|
|
78
|
+
|
|
79
|
+
| Backend | Install | Config |
|
|
80
|
+
|---------|---------|--------|
|
|
81
|
+
| **Kuzu** (default) | included | `MEMORY_GRAPH_PROVIDER=kuzu` |
|
|
82
|
+
| **Neo4j** | `pip install hy-memory[graph]` | `MEMORY_GRAPH_PROVIDER=neo4j` |
|
|
83
|
+
|
|
84
|
+
## Documentation
|
|
85
|
+
|
|
86
|
+
- [Usage Guide](docs/usage.md) — Detailed API documentation and examples
|
|
87
|
+
- [Environment Reference](docs/env_reference.md) — All configuration options
|
|
88
|
+
- [Contributing](CONTRIBUTING.md) — How to contribute
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""
|
|
2
|
+
HY Memory - 核心 SDK
|
|
3
|
+
|
|
4
|
+
工业级智能体记忆系统核心框架。
|
|
5
|
+
|
|
6
|
+
快速开始:
|
|
7
|
+
export OPENAI_API_KEY="sk-your-key-here"
|
|
8
|
+
|
|
9
|
+
from hy_memory import HyMemoryClient
|
|
10
|
+
|
|
11
|
+
# 最简用法 — 只需设置 OPENAI_API_KEY 环境变量
|
|
12
|
+
client = HyMemoryClient(user_id="test_user")
|
|
13
|
+
client.add("用户喜欢科幻电影")
|
|
14
|
+
results = client.search("用户喜欢什么?")
|
|
15
|
+
client.close()
|
|
16
|
+
|
|
17
|
+
默认配置:
|
|
18
|
+
- embedder: OpenAI text-embedding-3-small (1536 维)
|
|
19
|
+
- llm: OpenAI gpt-4.1-nano
|
|
20
|
+
- vector_store: Chroma 本地嵌入式 (零外部依赖)
|
|
21
|
+
|
|
22
|
+
只需设置 OPENAI_API_KEY 环境变量即可运行。
|
|
23
|
+
|
|
24
|
+
# 自定义配置
|
|
25
|
+
client = HyMemoryClient.from_config({
|
|
26
|
+
"vector_store": {"provider": "qdrant"},
|
|
27
|
+
"graph_store": {
|
|
28
|
+
"provider": "neo4j",
|
|
29
|
+
"url": "bolt://localhost:7687",
|
|
30
|
+
"username": "neo4j",
|
|
31
|
+
"password": "password",
|
|
32
|
+
},
|
|
33
|
+
"enable_graph": True,
|
|
34
|
+
}, user_id="test_user")
|
|
35
|
+
|
|
36
|
+
数据隔离 (两级):
|
|
37
|
+
- user_id: 一级 key — 每个用户唯一的记忆库
|
|
38
|
+
- agent_id: 二级 key — 同一用户下不同 Agent 场景的隔离
|
|
39
|
+
|
|
40
|
+
安装方式:
|
|
41
|
+
pip install hy-memory # 核心依赖 (含 Chroma,开箱即用)
|
|
42
|
+
pip install hy-memory[qdrant] # + Qdrant 向量库
|
|
43
|
+
pip install hy-memory[faiss] # + FAISS 向量库
|
|
44
|
+
pip install hy-memory[all] # 包含所有可选依赖
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
from importlib.metadata import version as _get_version
|
|
49
|
+
__version__ = _get_version("hy-memory")
|
|
50
|
+
except Exception:
|
|
51
|
+
__version__ = "1.0.0"
|
|
52
|
+
|
|
53
|
+
# ====== 用户级 API(推荐) ======
|
|
54
|
+
from .client import HyMemoryClient
|
|
55
|
+
from .inspector import MemoryInspector
|
|
56
|
+
|
|
57
|
+
# ====== 配置 ======
|
|
58
|
+
from .config import MemoryConfig
|
|
59
|
+
|
|
60
|
+
# ====== 高级 API(按需使用) ======
|
|
61
|
+
from .pipelines import (
|
|
62
|
+
ComponentFactory,
|
|
63
|
+
PipelineConfig,
|
|
64
|
+
WritePipeline,
|
|
65
|
+
ReadPipeline,
|
|
66
|
+
ChatMessage,
|
|
67
|
+
WriteRequest,
|
|
68
|
+
WriteResponse,
|
|
69
|
+
ReadRequest,
|
|
70
|
+
ReadResponse,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# ====== 数据模型 ======
|
|
74
|
+
from .models import (
|
|
75
|
+
MemoryLayer,
|
|
76
|
+
MemoryNode,
|
|
77
|
+
MemoryEntry,
|
|
78
|
+
MemoryMetadata,
|
|
79
|
+
MemoryScore,
|
|
80
|
+
MemoryInputType,
|
|
81
|
+
AgentProcessMode,
|
|
82
|
+
TaskStatus,
|
|
83
|
+
DeleteScope,
|
|
84
|
+
QAPair,
|
|
85
|
+
AddRequest,
|
|
86
|
+
AddResponse,
|
|
87
|
+
AsyncAddResponse,
|
|
88
|
+
RecallRequest,
|
|
89
|
+
RecallResponse,
|
|
90
|
+
UpdateRequest,
|
|
91
|
+
UpdateResponse,
|
|
92
|
+
DeleteRequest,
|
|
93
|
+
DeleteResponse,
|
|
94
|
+
BatchDeleteRequest,
|
|
95
|
+
BatchDeleteResponse,
|
|
96
|
+
GetRequest,
|
|
97
|
+
GetResponse,
|
|
98
|
+
ListRequest,
|
|
99
|
+
ListResponse,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
__all__ = [
|
|
104
|
+
"__version__",
|
|
105
|
+
# 用户级 API
|
|
106
|
+
"HyMemoryClient",
|
|
107
|
+
"MemoryInspector",
|
|
108
|
+
# 配置
|
|
109
|
+
"MemoryConfig",
|
|
110
|
+
# 高级 API
|
|
111
|
+
"ComponentFactory",
|
|
112
|
+
"PipelineConfig",
|
|
113
|
+
"WritePipeline",
|
|
114
|
+
"ReadPipeline",
|
|
115
|
+
"ChatMessage",
|
|
116
|
+
"WriteRequest",
|
|
117
|
+
"WriteResponse",
|
|
118
|
+
"ReadRequest",
|
|
119
|
+
"ReadResponse",
|
|
120
|
+
# 数据模型
|
|
121
|
+
"MemoryLayer",
|
|
122
|
+
"MemoryNode",
|
|
123
|
+
"MemoryEntry",
|
|
124
|
+
"MemoryMetadata",
|
|
125
|
+
"MemoryScore",
|
|
126
|
+
"MemoryInputType",
|
|
127
|
+
"AgentProcessMode",
|
|
128
|
+
"TaskStatus",
|
|
129
|
+
"DeleteScope",
|
|
130
|
+
"QAPair",
|
|
131
|
+
"AddRequest",
|
|
132
|
+
"AddResponse",
|
|
133
|
+
"AsyncAddResponse",
|
|
134
|
+
"RecallRequest",
|
|
135
|
+
"RecallResponse",
|
|
136
|
+
"UpdateRequest",
|
|
137
|
+
"UpdateResponse",
|
|
138
|
+
"DeleteRequest",
|
|
139
|
+
"DeleteResponse",
|
|
140
|
+
"BatchDeleteRequest",
|
|
141
|
+
"BatchDeleteResponse",
|
|
142
|
+
"GetRequest",
|
|
143
|
+
"GetResponse",
|
|
144
|
+
"ListRequest",
|
|
145
|
+
"ListResponse",
|
|
146
|
+
]
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Agent Memory - 智能层 (Agent Layer)
|
|
3
|
+
|
|
4
|
+
基于 LLM 的智能处理能力,提供语义理解、信息提取、推理判断等功能。
|
|
5
|
+
该层是可选的,关闭后系统仍能正常工作。
|
|
6
|
+
|
|
7
|
+
包含模块:
|
|
8
|
+
- MemAgent: 智能体协调器,统一入口
|
|
9
|
+
- Summarizer: Lite+Agent pipeline 摘要生成器 (L3_SUMMARY)
|
|
10
|
+
- Abstractor: System 2 全量摘要智能体 (Session摘要/Schema归纳/Profile摘要)
|
|
11
|
+
- Extractor: 提取智能体,提取结构化信息 (V2: 轻量提取/深度提取双模式)
|
|
12
|
+
- Reflector: 反思智能体,检测冲突和更新 (V2: UpdateType分类/冲突检测/隐式推断)
|
|
13
|
+
- EmotionAnalyzer: 情绪分析智能体,valence + arousal 双维标注
|
|
14
|
+
- IntentionDetector: 意图检测智能体,前瞻性记忆 + 主动关怀
|
|
15
|
+
- LLMProvider: LLM 提供器,统一的模型调用接口
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
# Lite+Agent pipeline
|
|
19
|
+
from .mem_agent import MemAgent, AgentResult, ProcessMode
|
|
20
|
+
from .summarizer import Summarizer, SummaryResult
|
|
21
|
+
from .extractor import Extractor, ExtractResult
|
|
22
|
+
from .reflector import Reflector, ReflectResult, ConflictType, ConflictAction
|
|
23
|
+
from .llm_provider import LLMProvider, LLMResponse, LLMConfig, LLMBackend
|
|
24
|
+
|
|
25
|
+
# V2 Extractor
|
|
26
|
+
from .extractor import ExtractMode, V2ExtractResult
|
|
27
|
+
|
|
28
|
+
# System 2 / Pro Pipeline Abstractor
|
|
29
|
+
from .abstractor import Abstractor, SessionSummaryResult, SchemaAbstractResult, ProfileSummaryResult
|
|
30
|
+
|
|
31
|
+
# V2 Reflector
|
|
32
|
+
from .reflector import (
|
|
33
|
+
V2ConflictType,
|
|
34
|
+
UpdateTypeResult,
|
|
35
|
+
ConflictDetectionResult,
|
|
36
|
+
ImplicitSignal,
|
|
37
|
+
ImplicitInferenceResult,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# V2 Emotion Analyzer
|
|
41
|
+
from .emotion_analyzer import EmotionAnalyzer, EmotionAnalysisConfig, EmotionResult
|
|
42
|
+
|
|
43
|
+
# V2 Intention Detector
|
|
44
|
+
from .intention_detector import (
|
|
45
|
+
IntentionDetector,
|
|
46
|
+
IntentionDetectorConfig,
|
|
47
|
+
DetectedIntention,
|
|
48
|
+
IntentionDetectResult,
|
|
49
|
+
TriggeredIntentionItem,
|
|
50
|
+
IntentionTriggerResult,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
__all__ = [
|
|
54
|
+
# MemAgent
|
|
55
|
+
"MemAgent",
|
|
56
|
+
"AgentResult",
|
|
57
|
+
"ProcessMode",
|
|
58
|
+
# Summarizer (Lite+Agent)
|
|
59
|
+
"Summarizer",
|
|
60
|
+
"SummaryResult",
|
|
61
|
+
# Abstractor (System 2)
|
|
62
|
+
"Abstractor",
|
|
63
|
+
"SessionSummaryResult",
|
|
64
|
+
"SchemaAbstractResult",
|
|
65
|
+
"ProfileSummaryResult",
|
|
66
|
+
# Extractor (V1)
|
|
67
|
+
"Extractor",
|
|
68
|
+
"ExtractResult",
|
|
69
|
+
# Extractor (V2)
|
|
70
|
+
"ExtractMode",
|
|
71
|
+
"V2ExtractResult",
|
|
72
|
+
# Reflector (V1)
|
|
73
|
+
"Reflector",
|
|
74
|
+
"ReflectResult",
|
|
75
|
+
"ConflictType",
|
|
76
|
+
"ConflictAction",
|
|
77
|
+
# Reflector (V2)
|
|
78
|
+
"V2ConflictType",
|
|
79
|
+
"UpdateTypeResult",
|
|
80
|
+
"ConflictDetectionResult",
|
|
81
|
+
"ImplicitSignal",
|
|
82
|
+
"ImplicitInferenceResult",
|
|
83
|
+
# Emotion Analyzer (V2)
|
|
84
|
+
"EmotionAnalyzer",
|
|
85
|
+
"EmotionAnalysisConfig",
|
|
86
|
+
"EmotionResult",
|
|
87
|
+
# Intention Detector (V2)
|
|
88
|
+
"IntentionDetector",
|
|
89
|
+
"IntentionDetectorConfig",
|
|
90
|
+
"DetectedIntention",
|
|
91
|
+
"IntentionDetectResult",
|
|
92
|
+
"TriggeredIntentionItem",
|
|
93
|
+
"IntentionTriggerResult",
|
|
94
|
+
# LLMProvider
|
|
95
|
+
"LLMProvider",
|
|
96
|
+
"LLMResponse",
|
|
97
|
+
"LLMConfig",
|
|
98
|
+
"LLMBackend",
|
|
99
|
+
]
|