synaptic-memory 0.5.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.
- synaptic_memory-0.5.0/.claude/settings.local.json +8 -0
- synaptic_memory-0.5.0/.github/workflows/ci.yml +38 -0
- synaptic_memory-0.5.0/CHANGELOG.md +87 -0
- synaptic_memory-0.5.0/LICENSE +21 -0
- synaptic_memory-0.5.0/PKG-INFO +449 -0
- synaptic_memory-0.5.0/README.md +390 -0
- synaptic_memory-0.5.0/docker-compose.yml +22 -0
- synaptic_memory-0.5.0/docs/ARCHITECTURE.md +170 -0
- synaptic_memory-0.5.0/docs/COMPARISON.md +277 -0
- synaptic_memory-0.5.0/docs/PLAN-v0.5-scale.md +350 -0
- synaptic_memory-0.5.0/docs/ROADMAP.md +131 -0
- synaptic_memory-0.5.0/pyproject.toml +106 -0
- synaptic_memory-0.5.0/src/synaptic/__init__.py +72 -0
- synaptic_memory-0.5.0/src/synaptic/activity.py +261 -0
- synaptic_memory-0.5.0/src/synaptic/agent_search.py +385 -0
- synaptic_memory-0.5.0/src/synaptic/backends/__init__.py +1 -0
- synaptic_memory-0.5.0/src/synaptic/backends/composite.py +240 -0
- synaptic_memory-0.5.0/src/synaptic/backends/memory.py +215 -0
- synaptic_memory-0.5.0/src/synaptic/backends/minio_store.py +108 -0
- synaptic_memory-0.5.0/src/synaptic/backends/neo4j.py +521 -0
- synaptic_memory-0.5.0/src/synaptic/backends/postgresql.py +479 -0
- synaptic_memory-0.5.0/src/synaptic/backends/qdrant.py +135 -0
- synaptic_memory-0.5.0/src/synaptic/backends/sqlite.py +390 -0
- synaptic_memory-0.5.0/src/synaptic/cache.py +67 -0
- synaptic_memory-0.5.0/src/synaptic/consolidation.py +175 -0
- synaptic_memory-0.5.0/src/synaptic/exporter.py +120 -0
- synaptic_memory-0.5.0/src/synaptic/extensions/__init__.py +1 -0
- synaptic_memory-0.5.0/src/synaptic/extensions/embedder.py +143 -0
- synaptic_memory-0.5.0/src/synaptic/extensions/rewriter.py +60 -0
- synaptic_memory-0.5.0/src/synaptic/extensions/tagger_regex.py +48 -0
- synaptic_memory-0.5.0/src/synaptic/graph.py +349 -0
- synaptic_memory-0.5.0/src/synaptic/hebbian.py +97 -0
- synaptic_memory-0.5.0/src/synaptic/mcp/__init__.py +3 -0
- synaptic_memory-0.5.0/src/synaptic/mcp/__main__.py +5 -0
- synaptic_memory-0.5.0/src/synaptic/mcp/server.py +714 -0
- synaptic_memory-0.5.0/src/synaptic/models.py +130 -0
- synaptic_memory-0.5.0/src/synaptic/ontology.py +405 -0
- synaptic_memory-0.5.0/src/synaptic/protocols.py +98 -0
- synaptic_memory-0.5.0/src/synaptic/py.typed +0 -0
- synaptic_memory-0.5.0/src/synaptic/resonance.py +75 -0
- synaptic_memory-0.5.0/src/synaptic/search.py +131 -0
- synaptic_memory-0.5.0/src/synaptic/store.py +111 -0
- synaptic_memory-0.5.0/src/synaptic/synonyms.py +73 -0
- synaptic_memory-0.5.0/tests/conftest.py +66 -0
- synaptic_memory-0.5.0/tests/qa/__init__.py +1 -0
- synaptic_memory-0.5.0/tests/qa/conftest.py +169 -0
- synaptic_memory-0.5.0/tests/qa/data/github_commits.json +842 -0
- synaptic_memory-0.5.0/tests/qa/data/github_issues.json +1847 -0
- synaptic_memory-0.5.0/tests/qa/data/wikipedia_ko_tech.json +5677 -0
- synaptic_memory-0.5.0/tests/qa/test_edge_cases.py +313 -0
- synaptic_memory-0.5.0/tests/qa/test_learning_cycle.py +126 -0
- synaptic_memory-0.5.0/tests/qa/test_performance.py +115 -0
- synaptic_memory-0.5.0/tests/qa/test_search_quality.py +118 -0
- synaptic_memory-0.5.0/tests/test_activity.py +203 -0
- synaptic_memory-0.5.0/tests/test_agent_search.py +240 -0
- synaptic_memory-0.5.0/tests/test_backend_composite.py +200 -0
- synaptic_memory-0.5.0/tests/test_backend_memory.py +171 -0
- synaptic_memory-0.5.0/tests/test_backend_minio.py +94 -0
- synaptic_memory-0.5.0/tests/test_backend_neo4j.py +321 -0
- synaptic_memory-0.5.0/tests/test_backend_postgresql.py +186 -0
- synaptic_memory-0.5.0/tests/test_backend_qdrant.py +94 -0
- synaptic_memory-0.5.0/tests/test_backend_sqlite.py +128 -0
- synaptic_memory-0.5.0/tests/test_cache.py +69 -0
- synaptic_memory-0.5.0/tests/test_consolidation.py +141 -0
- synaptic_memory-0.5.0/tests/test_exporter.py +31 -0
- synaptic_memory-0.5.0/tests/test_extensions.py +80 -0
- synaptic_memory-0.5.0/tests/test_graph.py +222 -0
- synaptic_memory-0.5.0/tests/test_hebbian.py +96 -0
- synaptic_memory-0.5.0/tests/test_json_export.py +111 -0
- synaptic_memory-0.5.0/tests/test_models.py +96 -0
- synaptic_memory-0.5.0/tests/test_ontology.py +203 -0
- synaptic_memory-0.5.0/tests/test_resonance.py +64 -0
- synaptic_memory-0.5.0/tests/test_search.py +39 -0
- synaptic_memory-0.5.0/tests/test_synonyms.py +37 -0
- synaptic_memory-0.5.0/uv.lock +1723 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
check:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.12", "3.13"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
23
|
+
run: uv python install ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: uv sync --extra dev --extra sqlite
|
|
27
|
+
|
|
28
|
+
- name: Ruff check
|
|
29
|
+
run: uv run ruff check
|
|
30
|
+
|
|
31
|
+
- name: Ruff format
|
|
32
|
+
run: uv run ruff format --check
|
|
33
|
+
|
|
34
|
+
- name: Pyright
|
|
35
|
+
run: uv run pyright
|
|
36
|
+
|
|
37
|
+
- name: Tests
|
|
38
|
+
run: uv run pytest -v
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## v0.5.0 (2026-03-21)
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **Ontology Engine** — 동적 타입 계층, 속성 상속, 관계 제약 검증 (`OntologyRegistry`, `TypeDef`, `PropertyDef`, `RelationConstraint`)
|
|
7
|
+
- **Agent Activity Tracking** — 세션/tool call/decision/outcome 캡처 (`ActivityTracker`)
|
|
8
|
+
- **Intent-based Agent Search** — 6가지 검색 전략: similar_decisions, past_failures, related_rules, reasoning_chain, context_explore, general (`AgentSearch`, `SearchIntent`)
|
|
9
|
+
- **Intent 자동 추론** — 쿼리 키워드에서 intent 자동 판별 (`suggest_intent()`, `intent="auto"` 기본값)
|
|
10
|
+
- **Neo4j Backend** — native Cypher 그래프 순회, dual label, typed relationship, fulltext index
|
|
11
|
+
- **GraphTraversal Protocol** — `shortest_path()`, `pattern_match()`, `find_by_type_hierarchy()`
|
|
12
|
+
- **5축 Resonance Scoring** — context axis 추가 (세션 태그 Jaccard 유사도)
|
|
13
|
+
- **Node.properties** — 온톨로지 확장 속성 (dict[str, str]), 전 백엔드 지원
|
|
14
|
+
- **Ontology 영속화** — `save_ontology()` / `load_ontology()`로 그래프에 저장/복원
|
|
15
|
+
- **L3 강등 메커니즘** — 성공률 60% 미만 시 L3 → L2 강등
|
|
16
|
+
- **Consolidation 페이지네이션** — limit=1000 제한 제거, 전체 노드 배치 처리
|
|
17
|
+
- **link() 온톨로지 검증** — 관계 제약 위반 시 ValueError 발생
|
|
18
|
+
- **Hebbian adaptive learning rate** — `delta / (1 + 0.02 × maturity)`로 초기 빠른 학습, 이후 안정화
|
|
19
|
+
- **HybridSearch node_kinds 필터** — 검색 시 노드 타입 필터링
|
|
20
|
+
- **기본 에이전트 온톨로지** — `build_agent_ontology()`로 knowledge/agent_activity 타입 트리 제공
|
|
21
|
+
- **MCP 9개 tool 추가** (총 16개): agent_start_session, agent_log_action, agent_record_decision, agent_record_outcome, agent_find_similar, agent_get_reasoning_chain, agent_explore_context, ontology_define_type, ontology_query_schema
|
|
22
|
+
- **NodeKind 6개 추가**: tool_call, observation, reasoning, outcome, session, type_def
|
|
23
|
+
- **EdgeKind 5개 추가**: is_a, invoked, resulted_in, part_of, followed_by
|
|
24
|
+
- `docker-compose.yml` — Neo4j 개발 환경
|
|
25
|
+
- `docs/COMPARISON.md` — 기존 Agent Memory 시스템 비교 분석
|
|
26
|
+
- 185+ unit tests, 22 Neo4j integration tests
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
- `graph.agent_search()` 기본 intent가 `"auto"` (키워드 기반 자동 추론)
|
|
30
|
+
- `ResonanceWeights`에 `context` 필드 추가 (기본값 0.0, 하위호환)
|
|
31
|
+
- SQLite/PostgreSQL backend에 `properties_json` 컬럼 자동 마이그레이션 (v0.4 → v0.5)
|
|
32
|
+
- pyproject.toml: `neo4j`, `scale` extras 추가, version 0.5.0
|
|
33
|
+
|
|
34
|
+
## v0.4.0 (2026-03-21)
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
- **MCP Server** — 7개 tool (knowledge_search/add/link/reinforce/stats/export/consolidate)
|
|
38
|
+
- **SQLite Backend** — FTS5, recursive CTE, WAL mode
|
|
39
|
+
- **QA Test Suite** — Wikipedia 169건 + GitHub 368건 실제 데이터 검증
|
|
40
|
+
- `synaptic-mcp` CLI entry point
|
|
41
|
+
|
|
42
|
+
## v0.3.0 (2026-03-21)
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
- **Protocol 구현체** — LLM QueryRewriter, RegexTagExtractor, EmbeddingProvider
|
|
46
|
+
- **LRU Cache** — NodeCache with hit rate tracking
|
|
47
|
+
- **JSON Exporter** — 구조화된 JSON export
|
|
48
|
+
- **Node Merge** — 중복 노드 병합 + 엣지 재연결
|
|
49
|
+
- **Find Duplicates** — 제목 유사도 기반 중복 탐지
|
|
50
|
+
|
|
51
|
+
## v0.2.0 (2026-03-21)
|
|
52
|
+
|
|
53
|
+
### Added
|
|
54
|
+
- **PostgreSQL backend** — asyncpg + pgvector HNSW + pg_trgm + recursive CTE
|
|
55
|
+
- Vector search with cosine distance (pgvector)
|
|
56
|
+
- Trigram fuzzy matching with graceful ILIKE fallback
|
|
57
|
+
- Hybrid search method: FTS + fuzzy + vector merged results
|
|
58
|
+
- Connection pooling (asyncpg Pool, min=2, max=10)
|
|
59
|
+
- Configurable `embedding_dim` parameter
|
|
60
|
+
- `execute_raw()` for admin/testing SQL
|
|
61
|
+
- `ResonanceWeights` added to public exports
|
|
62
|
+
- Configurable consolidation thresholds (TTL, promotion access counts)
|
|
63
|
+
- Edge direction type safety: `Literal["both", "incoming", "outgoing"]`
|
|
64
|
+
- SQLite batch operations with rollback on error
|
|
65
|
+
- README.md, ARCHITECTURE.md, ROADMAP.md documentation
|
|
66
|
+
- GitHub Actions CI (Python 3.12/3.13)
|
|
67
|
+
- Integration test suite for PostgreSQL (13 tests)
|
|
68
|
+
|
|
69
|
+
### Changed
|
|
70
|
+
- Consolidation constants now accept `__init__` parameters instead of module globals
|
|
71
|
+
|
|
72
|
+
## v0.1.0 (2026-03-21)
|
|
73
|
+
|
|
74
|
+
### Added
|
|
75
|
+
- Core models: Node, Edge, ActivatedNode, SearchResult, DigestResult
|
|
76
|
+
- Enums: NodeKind (9), EdgeKind (7), ConsolidationLevel (4)
|
|
77
|
+
- Protocols: StorageBackend, Digester, QueryRewriter, TagExtractor
|
|
78
|
+
- SynapticGraph facade: add, link, search, reinforce, consolidate, prune, decay
|
|
79
|
+
- Hybrid 3-stage search: FTS + fuzzy → synonym expansion → query rewrite
|
|
80
|
+
- Hebbian learning engine: co-activation reinforcement with anti-resonance
|
|
81
|
+
- 4-axis resonance scoring: relevance × importance × recency × vitality
|
|
82
|
+
- Memory consolidation cascade: L0→L1→L2→L3 with TTL and promotion
|
|
83
|
+
- Korean/English synonym map (38 groups)
|
|
84
|
+
- Markdown exporter
|
|
85
|
+
- MemoryBackend (dict-based, zero deps)
|
|
86
|
+
- SQLiteBackend (FTS5, recursive CTE, WAL mode)
|
|
87
|
+
- 93 unit tests, pyright strict, ruff clean
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PlateerLab
|
|
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.
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: synaptic-memory
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Brain-inspired knowledge graph for LLM agents — ontology, Hebbian learning, memory consolidation, intent-based search.
|
|
5
|
+
Project-URL: Homepage, https://github.com/PlateerLab/synaptic-memory
|
|
6
|
+
Project-URL: Repository, https://github.com/PlateerLab/synaptic-memory
|
|
7
|
+
Project-URL: Documentation, https://github.com/PlateerLab/synaptic-memory/blob/main/README.md
|
|
8
|
+
Project-URL: Changelog, https://github.com/PlateerLab/synaptic-memory/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Son Seongjun
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agent-memory,hebbian-learning,knowledge-graph,mcp,memory-consolidation,neo4j,ontology,qdrant,spreading-activation
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Framework :: AsyncIO
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Database :: Database Engines/Servers
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Provides-Extra: all
|
|
24
|
+
Requires-Dist: aiohttp>=3.9; extra == 'all'
|
|
25
|
+
Requires-Dist: aiosqlite>=0.20; extra == 'all'
|
|
26
|
+
Requires-Dist: asyncpg>=0.30; extra == 'all'
|
|
27
|
+
Requires-Dist: mcp[cli]>=1.5; extra == 'all'
|
|
28
|
+
Requires-Dist: miniopy-async>=1.21; extra == 'all'
|
|
29
|
+
Requires-Dist: neo4j>=5.25; extra == 'all'
|
|
30
|
+
Requires-Dist: pgvector>=0.3; extra == 'all'
|
|
31
|
+
Requires-Dist: qdrant-client>=1.12; extra == 'all'
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pyright>=1.1; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
36
|
+
Requires-Dist: ruff>=0.8; extra == 'dev'
|
|
37
|
+
Provides-Extra: embedding
|
|
38
|
+
Requires-Dist: aiohttp>=3.9; extra == 'embedding'
|
|
39
|
+
Provides-Extra: mcp
|
|
40
|
+
Requires-Dist: aiosqlite>=0.20; extra == 'mcp'
|
|
41
|
+
Requires-Dist: mcp[cli]>=1.5; extra == 'mcp'
|
|
42
|
+
Provides-Extra: minio
|
|
43
|
+
Requires-Dist: miniopy-async>=1.21; extra == 'minio'
|
|
44
|
+
Provides-Extra: neo4j
|
|
45
|
+
Requires-Dist: neo4j>=5.25; extra == 'neo4j'
|
|
46
|
+
Provides-Extra: postgresql
|
|
47
|
+
Requires-Dist: asyncpg>=0.30; extra == 'postgresql'
|
|
48
|
+
Requires-Dist: pgvector>=0.3; extra == 'postgresql'
|
|
49
|
+
Provides-Extra: qdrant
|
|
50
|
+
Requires-Dist: qdrant-client>=1.12; extra == 'qdrant'
|
|
51
|
+
Provides-Extra: scale
|
|
52
|
+
Requires-Dist: aiohttp>=3.9; extra == 'scale'
|
|
53
|
+
Requires-Dist: miniopy-async>=1.21; extra == 'scale'
|
|
54
|
+
Requires-Dist: neo4j>=5.25; extra == 'scale'
|
|
55
|
+
Requires-Dist: qdrant-client>=1.12; extra == 'scale'
|
|
56
|
+
Provides-Extra: sqlite
|
|
57
|
+
Requires-Dist: aiosqlite>=0.20; extra == 'sqlite'
|
|
58
|
+
Description-Content-Type: text/markdown
|
|
59
|
+
|
|
60
|
+
# Synaptic Memory
|
|
61
|
+
|
|
62
|
+
LLM/멀티에이전트를 위한 뇌 기반 지식 그래프.
|
|
63
|
+
|
|
64
|
+
에이전트가 운영 중에 만들어내는 모든 데이터 — tool call, 의사결정, 결과, 학습 — 를 Graph DB에 온톨로지로 구축하고, 나중에 에이전트가 스스로 검색·추론할 수 있게 하는 라이브러리 + MCP 서버.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Why — 이 프로젝트가 풀려는 문제
|
|
69
|
+
|
|
70
|
+
LLM 에이전트는 **기억하지 못한다.** 매번 같은 실수를 반복하고, 과거의 성공 패턴을 활용하지 못하고, 팀의 축적된 지식에 접근하지 못한다.
|
|
71
|
+
|
|
72
|
+
기존 RAG는 "문서를 잘게 잘라서 벡터로 검색"하는 데 그친다. 하지만 에이전트에게 필요한 건 문서 검색이 아니라 **경험의 구조화**다:
|
|
73
|
+
|
|
74
|
+
- "지난번 이런 상황에서 어떤 결정을 했고, 결과가 어땠지?"
|
|
75
|
+
- "이 패턴이 실패했던 적이 있나? 왜?"
|
|
76
|
+
- "이 도구를 쓸 때 지켜야 할 규칙이 뭐지?"
|
|
77
|
+
|
|
78
|
+
Synaptic Memory는 이 문제를 **뇌의 작동 방식**에서 답을 가져온다.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Design Philosophy — 뇌에서 빌려온 네 가지 원리
|
|
83
|
+
|
|
84
|
+
### 1. Spreading Activation — 연상 검색
|
|
85
|
+
|
|
86
|
+
뇌는 "deploy"라는 단어를 들으면 CI/CD, rollback, 장애, 모니터링이 함께 활성화된다. 키워드 매칭이 아니라 **연결된 개념이 함께 떠오르는 것**.
|
|
87
|
+
|
|
88
|
+
Synaptic Memory의 검색도 동일하게 작동한다:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
"배포" 검색
|
|
92
|
+
→ FTS 매칭: [CI/CD 파이프라인, 배포 자동화]
|
|
93
|
+
→ 이웃 활성화: [롤백 전략, 카나리 배포, 장애 대응 규칙]
|
|
94
|
+
→ Resonance 정렬: 최근성 × 중요도 × 성공률 × 맥락 친화도
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
텍스트가 아니라 **지식의 그래프 구조**를 따라 탐색한다. 이것이 RAG와의 근본적 차이.
|
|
98
|
+
|
|
99
|
+
### 2. Hebbian Learning — "함께 성공한 것은 더 강하게 연결된다"
|
|
100
|
+
|
|
101
|
+
뇌의 시냅스는 함께 발화하면 강화된다 (Hebb's Rule). Synaptic Memory는 이를 그대로 구현한다:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
에이전트가 [PostgreSQL 선택] + [벡터 검색 구현]을 함께 사용 → 성공
|
|
105
|
+
→ 두 노드 사이 edge weight += 0.1
|
|
106
|
+
→ 다음 검색 시 하나를 찾으면 다른 하나도 함께 활성화
|
|
107
|
+
|
|
108
|
+
에이전트가 [테스트 스킵] + [프로덕션 배포]를 함께 사용 → 실패
|
|
109
|
+
→ edge weight -= 0.15 (실패는 더 강하게 학습)
|
|
110
|
+
→ 다음에 "테스트 스킵"을 검색하면 실패 경험이 먼저 뜬다
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
에이전트가 명시적으로 "이건 나쁜 패턴이야"라고 태깅할 필요 없다. **사용하고 결과를 기록하면 그래프가 스스로 학습**한다. Adaptive learning rate로 초기에는 빠르게, 성숙하면 안정적으로 학습한다.
|
|
114
|
+
|
|
115
|
+
### 3. Memory Consolidation — 중요한 기억만 남기기
|
|
116
|
+
|
|
117
|
+
사람은 잠을 자는 동안 단기기억을 장기기억으로 전환한다. 자주 떠올린 기억은 강화되고, 안 쓰는 기억은 사라진다.
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
L0 (Raw, 72h) ← 에이전트가 만든 모든 기록. 72시간 후 미접근 시 삭제.
|
|
121
|
+
↓ 3회 이상 접근
|
|
122
|
+
L1 (Sprint, 90d) ← 반복 참조된 지식. 90일간 유지.
|
|
123
|
+
↓ 10회 이상 접근
|
|
124
|
+
L2 (Monthly, 365d) ← 검증된 지식. 1년간 유지.
|
|
125
|
+
↓ 성공률 80%+
|
|
126
|
+
L3 (Permanent) ← 조직의 핵심 지식. 영구 보존.
|
|
127
|
+
↓ 성공률 60% 미만
|
|
128
|
+
L2 (강등) ← 더 이상 유효하지 않은 지식은 강등.
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
이걸 안 하면? 에이전트가 만들어내는 데이터가 무한히 쌓여서 검색 품질이 떨어진다. **쓰이는 지식만 살아남는 자연선택**.
|
|
132
|
+
|
|
133
|
+
### 4. Ontology — 지식에 구조를 부여하기
|
|
134
|
+
|
|
135
|
+
플랫한 key-value 저장소에서는 "이 결정의 근거가 뭐였지?"를 물을 수 없다. 온톨로지는 **지식의 스키마**를 정의한다:
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
Decision --[resulted_in]--> Outcome --[learned_from]<-- Lesson
|
|
139
|
+
|
|
|
140
|
+
+--[depends_on]--> Context
|
|
141
|
+
+--[part_of]--> Session
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
타입 계층으로 "tool_call은 agent_activity의 하위 타입"이라는 관계를 표현하고, "resulted_in 엣지는 Decision에서 Outcome으로만 연결 가능"이라는 제약을 건다. 이 구조 덕분에 에이전트는 단순 텍스트 매칭이 아니라 **의미적 관계를 따라 추론**할 수 있다.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## How It Works — 에이전트의 하루
|
|
149
|
+
|
|
150
|
+
전체 흐름을 하나의 시나리오로:
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
1. 에이전트 세션 시작
|
|
154
|
+
→ Session 노드 생성
|
|
155
|
+
|
|
156
|
+
2. 에이전트가 "DB 마이그레이션" 작업을 받음
|
|
157
|
+
→ agent_find_similar("DB 마이그레이션", intent="similar_decisions")
|
|
158
|
+
→ 과거 Decision 3건 + Outcome 3건 + Lesson 1건 반환
|
|
159
|
+
→ "지난번 zero-downtime 마이그레이션 성공했었네. 그때 사용한 전략은..."
|
|
160
|
+
|
|
161
|
+
3. 에이전트가 결정을 내림: "Blue-green 마이그레이션 사용"
|
|
162
|
+
→ Decision 노드 생성 (rationale, alternatives 포함)
|
|
163
|
+
→ 참조한 지식 노드에 depends_on 엣지
|
|
164
|
+
|
|
165
|
+
4. 에이전트가 도구를 실행
|
|
166
|
+
→ ToolCall 노드 생성 (tool_name, params, result, duration)
|
|
167
|
+
→ Session에 part_of + followed_by 체인
|
|
168
|
+
|
|
169
|
+
5. 결과 확인: 성공
|
|
170
|
+
→ Outcome 노드 생성 (success=true)
|
|
171
|
+
→ Decision --[resulted_in]--> Outcome 엣지
|
|
172
|
+
→ Hebbian reinforcement: 관련 노드 간 연결 강화
|
|
173
|
+
|
|
174
|
+
6. Consolidation (주기적)
|
|
175
|
+
→ 72시간 동안 안 쓴 L0 노드 삭제
|
|
176
|
+
→ 자주 참조된 노드 L1→L2 승격
|
|
177
|
+
→ 성공률 80%+ 노드 L3 (영구) 승격
|
|
178
|
+
→ 성공률 60% 미만 L3 노드 → L2 강등
|
|
179
|
+
→ edge weight < 0.1인 약한 연결 정리
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
이 사이클이 반복되면서 **에이전트의 경험이 그래프에 축적**되고, 시간이 지날수록 검색 품질이 올라간다.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Architecture
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
SynapticGraph (Facade)
|
|
190
|
+
│
|
|
191
|
+
├── OntologyRegistry ─── 타입 계층 + 속성 상속 + 제약 검증
|
|
192
|
+
├── ActivityTracker ──── 세션/tool call/decision/outcome 캡처
|
|
193
|
+
├── AgentSearch ──────── 6가지 intent 기반 검색 전략
|
|
194
|
+
├── HybridSearch ─────── FTS + fuzzy + vector → synonym → LLM rewrite
|
|
195
|
+
├── ResonanceScorer ──── 5축 (relevance × importance × recency × vitality × context)
|
|
196
|
+
├── HebbianEngine ────── co-activation 강화/약화 (adaptive rate)
|
|
197
|
+
├── ConsolidationCascade L0→L3 생명주기 + L3 강등
|
|
198
|
+
├── EmbeddingProvider ── 자동 벡터 생성 (vLLM/llama.cpp/Ollama)
|
|
199
|
+
├── NodeCache (LRU)
|
|
200
|
+
└── Exporters (Markdown, JSON)
|
|
201
|
+
│
|
|
202
|
+
StorageBackend (Protocol — 20개 메서드)
|
|
203
|
+
│
|
|
204
|
+
┌────┼──────────┬───────────────┬──────────────┐
|
|
205
|
+
│ │ │ │ │
|
|
206
|
+
Memory SQLite PostgreSQL Neo4j CompositeBackend
|
|
207
|
+
(dev) (FTS5) (pgvector) (Cypher) (Neo4j+Qdrant+MinIO)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**핵심 설계 결정:**
|
|
211
|
+
|
|
212
|
+
- **Protocol-based** — 코어가 백엔드를 모른다. SQLite든 Neo4j든 같은 API. 백엔드 교체 시 코드 변경 0.
|
|
213
|
+
- **Zero core deps** — 코어는 순수 Python. `pip install synaptic-memory`에 외부 의존성 없음.
|
|
214
|
+
- **CompositeBackend** — Neo4j(그래프+FTS) + Qdrant(벡터 ANN) + MinIO(blob)를 하나의 StorageBackend로 통합. 용도별 라우팅.
|
|
215
|
+
- **Auto-embedding** — EmbeddingProvider를 주입하면 `add()`/`search()` 시 자동으로 벡터 생성. vLLM, llama.cpp, Ollama, TEI 등 OpenAI-compatible 엔드포인트 호환.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## 5-axis Resonance Scoring
|
|
220
|
+
|
|
221
|
+
검색 결과는 단순 텍스트 유사도가 아니라 5개 축의 가중합으로 정렬된다:
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
Score = 0.35 × relevance 검색 매칭 점수 [0,1]
|
|
225
|
+
+ 0.20 × importance (success - failure) / access_count [0,1]
|
|
226
|
+
+ 0.15 × recency exp(-0.05 × days_since_update) [0,1]
|
|
227
|
+
+ 0.10 × vitality 주기적 decay ×0.95 [0,1]
|
|
228
|
+
+ 0.20 × context 현재 세션 태그와의 Jaccard 유사도 [0,1]
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Intent별로 가중치가 다르다. `past_failures`는 importance(성공률)에 0.35를, `context_explore`는 context(태그 친화도)에 0.40을 준다. 에이전트가 "왜 이걸 찾고 있는지"에 따라 **같은 쿼리라도 다른 결과**가 나온다.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Install
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
pip install synaptic-memory # 코어 (zero deps)
|
|
239
|
+
pip install synaptic-memory[sqlite] # + SQLite
|
|
240
|
+
pip install synaptic-memory[neo4j] # + Neo4j
|
|
241
|
+
pip install synaptic-memory[neo4j,embedding] # + Neo4j + auto-embedding
|
|
242
|
+
pip install synaptic-memory[scale] # Neo4j + Qdrant + MinIO + embedding
|
|
243
|
+
pip install synaptic-memory[mcp] # + MCP server
|
|
244
|
+
pip install synaptic-memory[all] # 전부
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Quick Start
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
from synaptic.backends.memory import MemoryBackend
|
|
251
|
+
from synaptic import SynapticGraph, ActivityTracker, NodeKind, build_agent_ontology
|
|
252
|
+
|
|
253
|
+
async def main():
|
|
254
|
+
backend = MemoryBackend()
|
|
255
|
+
await backend.connect()
|
|
256
|
+
|
|
257
|
+
graph = SynapticGraph(backend, ontology=build_agent_ontology())
|
|
258
|
+
tracker = ActivityTracker(graph)
|
|
259
|
+
|
|
260
|
+
# 세션 시작
|
|
261
|
+
session = await tracker.start_session(agent_id="my-agent")
|
|
262
|
+
|
|
263
|
+
# 과거 경험 검색 (intent 자동 추론)
|
|
264
|
+
result = await graph.agent_search("DB 마이그레이션 실패")
|
|
265
|
+
# → intent="past_failures" 자동 선택
|
|
266
|
+
|
|
267
|
+
# 결정 기록
|
|
268
|
+
decision = await tracker.record_decision(
|
|
269
|
+
session.id,
|
|
270
|
+
title="PostgreSQL 선택",
|
|
271
|
+
rationale="벡터 검색 + ACID 필요",
|
|
272
|
+
alternatives=["MongoDB", "SQLite"],
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
# 결과 기록 → 자동 Hebbian learning
|
|
276
|
+
await tracker.record_outcome(
|
|
277
|
+
decision.id,
|
|
278
|
+
title="마이그레이션 성공",
|
|
279
|
+
content="Zero downtime, 벡터 검색 정상 작동",
|
|
280
|
+
success=True,
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
await backend.close()
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Auto-Embedding (vLLM / llama.cpp / Ollama)
|
|
287
|
+
|
|
288
|
+
EmbeddingProvider를 주입하면 모든 노드가 자동 임베딩 + 벡터 검색 활성화:
|
|
289
|
+
|
|
290
|
+
```python
|
|
291
|
+
from synaptic import SynapticGraph, OpenAIEmbeddingProvider
|
|
292
|
+
|
|
293
|
+
# vLLM, llama.cpp, Ollama, TEI — 어디든 동일한 인터페이스
|
|
294
|
+
embedder = OpenAIEmbeddingProvider(
|
|
295
|
+
"http://gpu-server:8080/v1", # OpenAI-compatible 엔드포인트
|
|
296
|
+
model="BAAI/bge-m3",
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
graph = SynapticGraph(backend, embedder=embedder)
|
|
300
|
+
|
|
301
|
+
# 자동: title+content → 벡터 생성 → Qdrant 저장
|
|
302
|
+
await graph.add("배포 전략", "Blue-green 배포로 zero downtime 달성")
|
|
303
|
+
|
|
304
|
+
# 자동: 쿼리 → 벡터 생성 → FTS + fuzzy + vector 동시 검색
|
|
305
|
+
result = await graph.search("배포 방식")
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Scale: CompositeBackend
|
|
309
|
+
|
|
310
|
+
Neo4j(그래프) + Qdrant(벡터) + MinIO(blob)를 하나의 StorageBackend로:
|
|
311
|
+
|
|
312
|
+
```python
|
|
313
|
+
from synaptic.backends.composite import CompositeBackend
|
|
314
|
+
from synaptic.backends.neo4j import Neo4jBackend
|
|
315
|
+
from synaptic.backends.qdrant import QdrantBackend
|
|
316
|
+
from synaptic.backends.minio_store import MinIOBackend
|
|
317
|
+
|
|
318
|
+
composite = CompositeBackend(
|
|
319
|
+
graph=Neo4jBackend("bolt://localhost:7687"),
|
|
320
|
+
vector=QdrantBackend("http://localhost:6333"),
|
|
321
|
+
blob=MinIOBackend("localhost:9000", access_key="minio", secret_key="secret"),
|
|
322
|
+
)
|
|
323
|
+
await composite.connect()
|
|
324
|
+
graph = SynapticGraph(composite, embedder=embedder)
|
|
325
|
+
|
|
326
|
+
# 내부 라우팅:
|
|
327
|
+
# - embedding → Qdrant에 자동 저장
|
|
328
|
+
# - content > 100KB → MinIO에 자동 offload
|
|
329
|
+
# - 나머지 → Neo4j (그래프 + FTS)
|
|
330
|
+
# - search_vector → Qdrant ANN → Neo4j batch get
|
|
331
|
+
# - graph traversal → Neo4j Cypher native
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## Ontology
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
from synaptic import OntologyRegistry, TypeDef, PropertyDef, build_agent_ontology
|
|
338
|
+
|
|
339
|
+
ontology = build_agent_ontology()
|
|
340
|
+
|
|
341
|
+
# 커스텀 타입 추가 (상속 지원)
|
|
342
|
+
ontology.register_type(TypeDef(
|
|
343
|
+
name="incident",
|
|
344
|
+
parent="agent_activity",
|
|
345
|
+
description="Production incident",
|
|
346
|
+
properties=[
|
|
347
|
+
PropertyDef(name="severity", value_type="str", required=True),
|
|
348
|
+
PropertyDef(name="resolved", value_type="bool"),
|
|
349
|
+
],
|
|
350
|
+
))
|
|
351
|
+
|
|
352
|
+
# 계층/상속/검증
|
|
353
|
+
ontology.is_a("incident", "agent_activity") # True
|
|
354
|
+
ontology.infer_properties("incident") # parent 속성 포함
|
|
355
|
+
ontology.validate_node("incident", {}) # ["Missing 'severity'"]
|
|
356
|
+
ontology.validate_edge("resulted_in", "concept", "outcome") # ["source not in domains"]
|
|
357
|
+
|
|
358
|
+
graph = SynapticGraph(backend, ontology=ontology)
|
|
359
|
+
# → graph.add(), graph.link() 시 자동 검증
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### 기본 온톨로지
|
|
363
|
+
|
|
364
|
+
```
|
|
365
|
+
knowledge agent_activity
|
|
366
|
+
├── concept ├── session (agent_id, status)
|
|
367
|
+
├── entity ├── tool_call (tool_name*, success, duration_ms)
|
|
368
|
+
├── lesson ├── observation
|
|
369
|
+
├── decision (rationale*) ├── reasoning
|
|
370
|
+
├── rule └── outcome (success*, impact)
|
|
371
|
+
└── artifact
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## Backends
|
|
375
|
+
|
|
376
|
+
| Backend | 그래프 순회 | 벡터 검색 | 스케일 | 용도 |
|
|
377
|
+
|---------|-----------|----------|-------|------|
|
|
378
|
+
| `MemoryBackend` | Python BFS | cosine | ~10K | 테스트, 프로토타이핑 |
|
|
379
|
+
| `SQLiteBackend` | CTE 재귀 | ✗ | ~100K | 임베디드, 단일 프로세스 |
|
|
380
|
+
| `PostgreSQLBackend` | CTE 재귀 | pgvector HNSW | ~1M | 프로덕션, 벡터 검색 |
|
|
381
|
+
| `Neo4jBackend` | Cypher native | ✗ (Qdrant 위임) | ~10B | 대규모 그래프 |
|
|
382
|
+
| `QdrantBackend` | ✗ | HNSW + 양자화 | ~10B | 벡터 전용 (ANN) |
|
|
383
|
+
| `MinIOBackend` | ✗ | ✗ | ~10TB | blob 저장 (S3 호환) |
|
|
384
|
+
| `CompositeBackend` | Neo4j | Qdrant | ∞ | **통합 라우터** |
|
|
385
|
+
|
|
386
|
+
## MCP Server — 16 Tools
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
synaptic-mcp # stdio (Claude Code)
|
|
390
|
+
synaptic-mcp --db ./knowledge.db # SQLite
|
|
391
|
+
synaptic-mcp --embed-url http://localhost:8080/v1 # + auto-embedding
|
|
392
|
+
synaptic-mcp --embed-url http://localhost:8080/v1 --embed-model BAAI/bge-m3
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**Knowledge** (7) — `knowledge_search`, `knowledge_add`, `knowledge_link`, `knowledge_reinforce`, `knowledge_stats`, `knowledge_export`, `knowledge_consolidate`
|
|
396
|
+
|
|
397
|
+
**Agent Workflow** (4) — `agent_start_session`, `agent_log_action`, `agent_record_decision`, `agent_record_outcome`
|
|
398
|
+
|
|
399
|
+
**Semantic Search** (3) — `agent_find_similar`, `agent_get_reasoning_chain`, `agent_explore_context`
|
|
400
|
+
|
|
401
|
+
**Ontology** (2) — `ontology_define_type`, `ontology_query_schema`
|
|
402
|
+
|
|
403
|
+
## Data Model
|
|
404
|
+
|
|
405
|
+
### Node Types (15)
|
|
406
|
+
|
|
407
|
+
| Category | Types |
|
|
408
|
+
|----------|-------|
|
|
409
|
+
| Knowledge | concept, entity, lesson, decision, rule, artifact, agent, task, sprint |
|
|
410
|
+
| Agent Activity | tool_call, observation, reasoning, outcome, session, type_def |
|
|
411
|
+
|
|
412
|
+
### Edge Types (12)
|
|
413
|
+
|
|
414
|
+
| Category | Types |
|
|
415
|
+
|----------|-------|
|
|
416
|
+
| Knowledge | related, caused, learned_from, depends_on, produced, contradicts, supersedes |
|
|
417
|
+
| Ontology & Activity | is_a, invoked, resulted_in, part_of, followed_by |
|
|
418
|
+
|
|
419
|
+
### Consolidation Levels
|
|
420
|
+
|
|
421
|
+
| Level | TTL | Promotion | Demotion |
|
|
422
|
+
|-------|-----|-----------|----------|
|
|
423
|
+
| L0 Raw | 72h | 3+ accesses → L1 | |
|
|
424
|
+
| L1 Sprint | 90d | 10+ accesses → L2 | |
|
|
425
|
+
| L2 Monthly | 365d | 10+ successes + 80%+ rate → L3 | |
|
|
426
|
+
| L3 Permanent | ∞ | 영구 보존 | 성공률 60% 미만 → L2 |
|
|
427
|
+
|
|
428
|
+
## Dev
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
uv sync --extra dev --extra sqlite --extra neo4j --extra qdrant --extra minio
|
|
432
|
+
uv run pytest -v # 185+ unit tests
|
|
433
|
+
uv run pytest -m neo4j # Neo4j integration (docker compose up neo4j)
|
|
434
|
+
uv run pytest -m qdrant # Qdrant integration (docker start qdrant)
|
|
435
|
+
uv run pytest -m composite # Full stack (Neo4j + Qdrant + MinIO)
|
|
436
|
+
uv run ruff check --fix && uv run ruff format
|
|
437
|
+
uv run pyright # strict mode
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
# 개발 인프라
|
|
442
|
+
docker compose up neo4j # Neo4j (bolt://localhost:7687)
|
|
443
|
+
docker start qdrant # Qdrant (http://localhost:6333)
|
|
444
|
+
# MinIO는 서버에서 직접 실행 (localhost:9000)
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## License
|
|
448
|
+
|
|
449
|
+
MIT
|