omem-os 0.0.1__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.
Files changed (121) hide show
  1. omem_os-0.0.1/.cursorrules +38 -0
  2. omem_os-0.0.1/.dockerignore +66 -0
  3. omem_os-0.0.1/.env.example +38 -0
  4. omem_os-0.0.1/.github/workflows/ci.yml +36 -0
  5. omem_os-0.0.1/.github/workflows/publish.yml +104 -0
  6. omem_os-0.0.1/.gitignore +46 -0
  7. omem_os-0.0.1/.pre-commit-config.yaml +45 -0
  8. omem_os-0.0.1/DEVELOPER.md +313 -0
  9. omem_os-0.0.1/Dockerfile +54 -0
  10. omem_os-0.0.1/LICENSE +21 -0
  11. omem_os-0.0.1/PKG-INFO +498 -0
  12. omem_os-0.0.1/README.md +451 -0
  13. omem_os-0.0.1/benchmarks/__init__.py +22 -0
  14. omem_os-0.0.1/benchmarks/agent_memory.py +278 -0
  15. omem_os-0.0.1/benchmarks/competitor.py +732 -0
  16. omem_os-0.0.1/benchmarks/concurrency.py +290 -0
  17. omem_os-0.0.1/benchmarks/integrity.py +274 -0
  18. omem_os-0.0.1/benchmarks/latency.py +202 -0
  19. omem_os-0.0.1/benchmarks/memory_profile.py +139 -0
  20. omem_os-0.0.1/benchmarks/production_stress_test.py +354 -0
  21. omem_os-0.0.1/benchmarks/rag_comparison.py +408 -0
  22. omem_os-0.0.1/benchmarks/run.py +51 -0
  23. omem_os-0.0.1/benchmarks/rust_sub_ms.py +69 -0
  24. omem_os-0.0.1/benchmarks/scalability.py +161 -0
  25. omem_os-0.0.1/benchmarks/scale.py +451 -0
  26. omem_os-0.0.1/benchmarks/suite.py +272 -0
  27. omem_os-0.0.1/docker-compose.yml +65 -0
  28. omem_os-0.0.1/examples/bharatsearch.py +65 -0
  29. omem_os-0.0.1/examples/demo.py +234 -0
  30. omem_os-0.0.1/examples/demo_ollama.py +1057 -0
  31. omem_os-0.0.1/examples/fico_investor_demo.py +183 -0
  32. omem_os-0.0.1/examples/memory_assistant.py +207 -0
  33. omem_os-0.0.1/examples/quickstart.py +24 -0
  34. omem_os-0.0.1/examples/save_session_to_omem.py +276 -0
  35. omem_os-0.0.1/llms.txt +36 -0
  36. omem_os-0.0.1/omem/__init__.py +29 -0
  37. omem_os-0.0.1/omem/api.py +465 -0
  38. omem_os-0.0.1/omem/backends/__init__.py +6 -0
  39. omem_os-0.0.1/omem/backends/base.py +42 -0
  40. omem_os-0.0.1/omem/backends/postgres.py +291 -0
  41. omem_os-0.0.1/omem/backends/sqlite.py +218 -0
  42. omem_os-0.0.1/omem/classify.py +262 -0
  43. omem_os-0.0.1/omem/cli.py +533 -0
  44. omem_os-0.0.1/omem/core/__init__.py +1 -0
  45. omem_os-0.0.1/omem/core/brain/__init__.py +0 -0
  46. omem_os-0.0.1/omem/core/brain/compression.py +191 -0
  47. omem_os-0.0.1/omem/core/brain/corruption_guard.py +96 -0
  48. omem_os-0.0.1/omem/core/brain/dream.py +277 -0
  49. omem_os-0.0.1/omem/core/brain/forgetting.py +231 -0
  50. omem_os-0.0.1/omem/core/brain/importance.py +358 -0
  51. omem_os-0.0.1/omem/core/brain/noise_gate.py +160 -0
  52. omem_os-0.0.1/omem/core/brain/prefetch.py +205 -0
  53. omem_os-0.0.1/omem/core/brain/quotas.py +110 -0
  54. omem_os-0.0.1/omem/core/brain/reflection.py +301 -0
  55. omem_os-0.0.1/omem/core/brain/secrets.py +79 -0
  56. omem_os-0.0.1/omem/core/brain/tms.py +188 -0
  57. omem_os-0.0.1/omem/core/brain/updater.py +184 -0
  58. omem_os-0.0.1/omem/core/distributed.py +203 -0
  59. omem_os-0.0.1/omem/core/engine/__init__.py +8 -0
  60. omem_os-0.0.1/omem/core/engine/add.py +147 -0
  61. omem_os-0.0.1/omem/core/engine/base.py +268 -0
  62. omem_os-0.0.1/omem/core/engine/lifecycle.py +245 -0
  63. omem_os-0.0.1/omem/core/engine/maintenance.py +74 -0
  64. omem_os-0.0.1/omem/core/engine/rag.py +238 -0
  65. omem_os-0.0.1/omem/core/engine/utils.py +104 -0
  66. omem_os-0.0.1/omem/core/engine.py +5 -0
  67. omem_os-0.0.1/omem/core/graph/__init__.py +0 -0
  68. omem_os-0.0.1/omem/core/graph/causal.py +58 -0
  69. omem_os-0.0.1/omem/core/graph/dependency.py +83 -0
  70. omem_os-0.0.1/omem/core/graph/knowledge.py +433 -0
  71. omem_os-0.0.1/omem/core/retrieval/__init__.py +0 -0
  72. omem_os-0.0.1/omem/core/retrieval/embeddings.py +187 -0
  73. omem_os-0.0.1/omem/core/retrieval/kv.py +47 -0
  74. omem_os-0.0.1/omem/core/retrieval/vector.py +82 -0
  75. omem_os-0.0.1/omem/core/utils/__init__.py +0 -0
  76. omem_os-0.0.1/omem/core/utils/cache.py +53 -0
  77. omem_os-0.0.1/omem/core/utils/concurrency.py +64 -0
  78. omem_os-0.0.1/omem/core/utils/inspector.py +74 -0
  79. omem_os-0.0.1/omem/core/utils/metrics.py +139 -0
  80. omem_os-0.0.1/omem/core/utils/snapshot.py +191 -0
  81. omem_os-0.0.1/omem/core/utils/write_buffer.py +120 -0
  82. omem_os-0.0.1/omem/eval/benchmark.py +131 -0
  83. omem_os-0.0.1/omem/eval/scenarios.json +65 -0
  84. omem_os-0.0.1/omem/integrations/__init__.py +1 -0
  85. omem_os-0.0.1/omem/integrations/agent_wrapper.py +80 -0
  86. omem_os-0.0.1/omem/integrations/crewai.py +111 -0
  87. omem_os-0.0.1/omem/integrations/langchain.py +126 -0
  88. omem_os-0.0.1/omem/integrations/mcp_server.py +379 -0
  89. omem_os-0.0.1/omem/types.py +168 -0
  90. omem_os-0.0.1/omem/viz/__init__.py +1 -0
  91. omem_os-0.0.1/omem/viz/server.py +282 -0
  92. omem_os-0.0.1/omem_os.egg-info/PKG-INFO +498 -0
  93. omem_os-0.0.1/omem_os.egg-info/SOURCES.txt +119 -0
  94. omem_os-0.0.1/omem_os.egg-info/dependency_links.txt +1 -0
  95. omem_os-0.0.1/omem_os.egg-info/entry_points.txt +2 -0
  96. omem_os-0.0.1/omem_os.egg-info/requires.txt +27 -0
  97. omem_os-0.0.1/omem_os.egg-info/top_level.txt +1 -0
  98. omem_os-0.0.1/pyproject.toml +74 -0
  99. omem_os-0.0.1/rust/Cargo.lock +414 -0
  100. omem_os-0.0.1/rust/Cargo.toml +17 -0
  101. omem_os-0.0.1/rust/src/lib.rs +248 -0
  102. omem_os-0.0.1/setup.cfg +4 -0
  103. omem_os-0.0.1/setup.py +9 -0
  104. omem_os-0.0.1/tests/__init__.py +0 -0
  105. omem_os-0.0.1/tests/conftest.py +23 -0
  106. omem_os-0.0.1/tests/test_api.py +88 -0
  107. omem_os-0.0.1/tests/test_backends.py +82 -0
  108. omem_os-0.0.1/tests/test_claude_mcp.py +100 -0
  109. omem_os-0.0.1/tests/test_cli.py +43 -0
  110. omem_os-0.0.1/tests/test_cli.sh +164 -0
  111. omem_os-0.0.1/tests/test_conversations.json +202 -0
  112. omem_os-0.0.1/tests/test_export_full.json +1289 -0
  113. omem_os-0.0.1/tests/test_mcp_final.py +118 -0
  114. omem_os-0.0.1/tests/test_mcp_integration.py +86 -0
  115. omem_os-0.0.1/tests/test_memory_os.py +281 -0
  116. omem_os-0.0.1/tests/test_nextgen.py +272 -0
  117. omem_os-0.0.1/tests/test_omem_full.py +183 -0
  118. omem_os-0.0.1/tests/test_truth_maintenance.py +46 -0
  119. omem_os-0.0.1/tests/test_types.py +97 -0
  120. omem_os-0.0.1/tests/test_v070_cognitive.py +69 -0
  121. omem_os-0.0.1/tests/test_v100_implementation.py +593 -0
@@ -0,0 +1,38 @@
1
+ # OMem Cursor Rules
2
+
3
+ You are an expert AI assistant helping developers build and optimize **OMem**—a fast, intelligent memory system for AI agents.
4
+
5
+ ## 1. Project Context
6
+ - **Objective**: Provide AI agents with human-like memory (context-aware, automatically scoring importance, consolidating generic information, and forgetting irrelevant data).
7
+ - **Core Languages**: Python (3.9+) and Rust.
8
+ - **Primary Dependencies**: `sentence-transformers`, `faiss-cpu`, `sqlite3`, `pydantic`.
9
+
10
+ ## 2. Architecture & Design
11
+ OMem consists of three main tiers:
12
+ 1. **API Layer (`omem/api.py`)**: Unified entry mechanism for the user (`OMem` class).
13
+ 2. **Logic & Engine (`omem/core/`)**:
14
+ - `brain/`: Advanced cognitive functions (dreaming/consolidation, importance scoring, conflict resolution, reflection).
15
+ - `engine/`: Execution pathways (ingestion/adding, RAG retrieval).
16
+ 3. **Performance Core (`rust/`)**: Rust-based engine compiled via PyO3 to `omem_rust`. Handles batched SIMD hybrid scoring (vector + keyword + recency + importance).
17
+
18
+ ## 3. Interaction with LLMs and AI Agents
19
+ OMem includes a **Model Context Protocol (MCP)** server natively.
20
+ - **Entry point**: `omem serve` or `omem.integrations.mcp_server`.
21
+ - If a user asks to integrate Claude Desktop, Cursor MCP, or an agent (like CrewAI / LangChain), point them to `omem/integrations/`.
22
+
23
+ ## 4. Coding Standards (Python)
24
+ - Use **strict type hints** (`Dict`, `List`, `Optional`, etc.) for all function signatures.
25
+ - Document any complex logic or reasoning within docstrings using clean markdown.
26
+ - Treat `core/brain` operations as modular heuristics. If you add a feature, ensure it does not slow down the synchronous `.add` or `.recall` loops unnecessarily.
27
+
28
+ ## 5. Coding Standards (Rust)
29
+ - Any operations processing entire arrays of memories or computing heavy distance metrics MUST go in the Rust core.
30
+ - Keep the boundary between Python and Rust thin (pass primitive arrays or simple structs).
31
+ - Remember to instruct the user to run `pip install -e .` if Rust files are modified.
32
+
33
+ ## 6. Testing
34
+ - `pytest tests/ -v` handles the test suite.
35
+ - When changing cognitive layers or adding new integrations, provide test cases simulating agent flows.
36
+
37
+ ## 7. Formatting & Brand Tone
38
+ - Maintain a highly professional but "cute and approachable" brand tone in user-facing documentation. Avoid overly academic jargon without practical examples.
@@ -0,0 +1,66 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ *.egg-info/
8
+ dist/
9
+ build/
10
+ .eggs/
11
+
12
+ # Virtual environments
13
+ .env
14
+ .venv
15
+ env/
16
+ venv/
17
+ ENV/
18
+ env.bak/
19
+ venv.bak/
20
+
21
+ # IDEs
22
+ .vscode/
23
+ .idea/
24
+ *.swp
25
+ *.swo
26
+ *~
27
+
28
+ # Testing
29
+ .pytest_cache/
30
+ .coverage
31
+ htmlcov/
32
+ .tox/
33
+
34
+ # Git
35
+ .git/
36
+ .gitignore
37
+ .gitattributes
38
+
39
+ # Documentation
40
+ *.md
41
+ docs/
42
+
43
+ # CI/CD
44
+ .github/
45
+
46
+ # Rust build artifacts (we copy only the compiled libs)
47
+ rust/target/debug/
48
+ rust/target/release/*.d
49
+ rust/target/release/*.rlib
50
+ rust/Cargo.lock
51
+
52
+ # Data and logs
53
+ *.db
54
+ *.db-shm
55
+ *.db-wal
56
+ logs/
57
+ data/
58
+
59
+ # OS
60
+ .DS_Store
61
+ Thumbs.db
62
+
63
+ # Development
64
+ examples/
65
+ tests/test_*.json
66
+ benchmarks/
@@ -0,0 +1,38 @@
1
+ # OMem Configuration
2
+
3
+ # Database Configuration
4
+ # Location where OMem stores memory data
5
+ # Default: ~/.omem/brain.db
6
+ OMEM_DB_PATH=~/.omem/brain.db
7
+
8
+ # Embedding Model Configuration
9
+ # Sentence-transformer model used for generating embeddings
10
+ # Options: all-MiniLM-L6-v2, all-mpnet-base-v2, paraphrase-multilingual-MiniLM-L12-v2
11
+ # Default: all-MiniLM-L6-v2
12
+ OMEM_MODEL=all-MiniLM-L6-v2
13
+
14
+ # Performance Configuration
15
+ # LRU cache size for hot memories (in number of entries)
16
+ # Higher values consume more memory but improve retrieval speed
17
+ # Default: 128000
18
+ OMEM_CACHE_SIZE=128000
19
+
20
+ # Database connection pool size for concurrent operations
21
+ # Increase for high-concurrency workloads
22
+ # Default: 5
23
+ OMEM_POOL_SIZE=5
24
+
25
+ # Logging Configuration
26
+ # Log level for OMem operations
27
+ # Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
28
+ # Default: INFO
29
+ OMEM_LOG_LEVEL=INFO
30
+
31
+ # MCP Server Configuration (optional)
32
+ # Port for MCP server when running `omem serve`
33
+ # Default: 3000
34
+ OMEM_MCP_PORT=3000
35
+
36
+ # Host for MCP server
37
+ # Default: localhost
38
+ OMEM_MCP_HOST=localhost
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ "dev", "staging", "prod", "main", "master" ]
6
+ pull_request:
7
+ branches: [ "dev", "staging", "prod", "main", "master" ]
8
+
9
+ jobs:
10
+ test:
11
+ name: Test and Lint
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v5
18
+ with:
19
+ python-version: "3.11"
20
+
21
+ - name: Install Rust
22
+ uses: dtolnay/rust-toolchain@stable
23
+
24
+ - name: Install Dependencies
25
+ run: |
26
+ python -m pip install --upgrade pip
27
+ pip install -e ".[dev]"
28
+ pip install ruff
29
+
30
+ - name: Lint with Ruff
31
+ run: |
32
+ ruff check .
33
+
34
+ - name: Test with pytest
35
+ run: |
36
+ pytest tests/ -v
@@ -0,0 +1,104 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build_wheels:
9
+ name: Build wheels on ${{ matrix.os }}
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ matrix:
13
+ os: [ubuntu-latest, windows-latest, macos-latest]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0
19
+
20
+ - name: Extract release version
21
+ shell: bash
22
+ run: echo "RELEASE_VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
23
+
24
+ - name: Set up QEMU
25
+ if: runner.os == 'Linux'
26
+ uses: docker/setup-qemu-action@v3
27
+ with:
28
+ platforms: arm64
29
+
30
+ - name: Install Rust toolchain
31
+ uses: dtolnay/rust-toolchain@stable
32
+
33
+ - name: Add macOS cross-compilation targets
34
+ if: runner.os == 'macOS'
35
+ run: |
36
+ rustup target add x86_64-apple-darwin
37
+ rustup target add aarch64-apple-darwin
38
+
39
+ - name: Build wheels
40
+ uses: pypa/cibuildwheel@v2.17.0
41
+ env:
42
+ CIBW_BUILD: "cp39-* cp310-* cp311-* cp312-* cp313-*"
43
+ CIBW_ARCHS_LINUX: "x86_64 aarch64"
44
+ CIBW_ARCHS_MACOS: "x86_64 arm64"
45
+ CIBW_BEFORE_ALL_LINUX: "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y"
46
+ CIBW_ENVIRONMENT: >-
47
+ PATH="$PATH:$HOME/.cargo/bin"
48
+ SETUPTOOLS_SCM_PRETEND_VERSION="${{ env.RELEASE_VERSION }}"
49
+ CIBW_ENVIRONMENT_MACOS: >-
50
+ PATH="$PATH:$HOME/.cargo/bin"
51
+ SETUPTOOLS_SCM_PRETEND_VERSION="${{ env.RELEASE_VERSION }}"
52
+ CIBW_ENVIRONMENT_WINDOWS: >-
53
+ SETUPTOOLS_SCM_PRETEND_VERSION="${{ env.RELEASE_VERSION }}"
54
+ CIBW_SKIP: "*-musllinux* pp*"
55
+ CIBW_BUILD_VERBOSITY: 1
56
+
57
+ - uses: actions/upload-artifact@v4
58
+ with:
59
+ name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
60
+ path: ./wheelhouse/*.whl
61
+
62
+ build_sdist:
63
+ name: Build source distribution
64
+ runs-on: ubuntu-latest
65
+ steps:
66
+ - uses: actions/checkout@v4
67
+ with:
68
+ fetch-depth: 0
69
+
70
+ - name: Extract release version
71
+ shell: bash
72
+ run: echo "RELEASE_VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
73
+
74
+ - name: Install Rust toolchain
75
+ uses: dtolnay/rust-toolchain@stable
76
+
77
+ - name: Build sdist
78
+ run: pipx run build --sdist
79
+ env:
80
+ SETUPTOOLS_SCM_PRETEND_VERSION: ${{ env.RELEASE_VERSION }}
81
+
82
+ - uses: actions/upload-artifact@v4
83
+ with:
84
+ name: cibw-sdist
85
+ path: dist/*.tar.gz
86
+
87
+ release:
88
+ name: Publish to PyPI
89
+ needs: [build_wheels, build_sdist]
90
+ runs-on: ubuntu-latest
91
+ environment: pypi
92
+ permissions:
93
+ id-token: write
94
+ steps:
95
+ - uses: actions/download-artifact@v4
96
+ with:
97
+ pattern: cibw-*
98
+ path: dist
99
+ merge-multiple: true
100
+
101
+ - name: Publish to PyPI
102
+ uses: pypa/gh-action-pypi-publish@release/v1
103
+ with:
104
+ skip_existing: true
@@ -0,0 +1,46 @@
1
+ # Byte-compiled
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Distribution
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ *.egg
11
+
12
+ # Virtual environments
13
+ .venv/
14
+ venv/
15
+ env/
16
+
17
+ # IDE
18
+ .idea/
19
+ .vscode/
20
+ *.swp
21
+ *.swo
22
+
23
+ # OS
24
+ .DS_Store
25
+ Thumbs.db
26
+
27
+ # Data
28
+ *.db
29
+ data/
30
+
31
+ # Testing
32
+ .pytest_cache/
33
+ htmlcov/
34
+ .coverage
35
+
36
+ # Rust build artifacts
37
+ rust/target/
38
+
39
+ # Linter cache
40
+ .ruff_cache/
41
+
42
+ # IDE / local config
43
+ .claude/settings.local.json
44
+
45
+ # Documentation
46
+ *.md
@@ -0,0 +1,45 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.5.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ exclude: ^tests/
7
+ - id: end-of-file-fixer
8
+ exclude: ^tests/
9
+ - id: check-yaml
10
+ - id: check-added-large-files
11
+ args: ['--maxkb=1000']
12
+ - id: check-json
13
+ - id: check-toml
14
+ - id: check-merge-conflict
15
+ - id: detect-private-key
16
+
17
+ - repo: https://github.com/astral-sh/ruff-pre-commit
18
+ rev: v0.3.0
19
+ hooks:
20
+ - id: ruff
21
+ args: [--fix, --exit-non-zero-on-fix]
22
+ exclude: ^(tests/|benchmarks/)
23
+
24
+ - repo: https://github.com/psf/black
25
+ rev: 24.2.0
26
+ hooks:
27
+ - id: black
28
+ language_version: python3.9
29
+ exclude: ^(tests/|benchmarks/)
30
+
31
+ - repo: https://github.com/pre-commit/mirrors-mypy
32
+ rev: v1.8.0
33
+ hooks:
34
+ - id: mypy
35
+ additional_dependencies: [types-all]
36
+ exclude: ^(tests/|benchmarks/|examples/)
37
+ args: [--ignore-missing-imports, --no-strict-optional]
38
+
39
+ - repo: local
40
+ hooks:
41
+ - id: no-commit-secrets
42
+ name: check for secrets in commit
43
+ entry: bash -c 'if git diff --cached | grep -iE "(api_key|secret_key|password|token|bearer)" | grep -v "OMEM_"; then exit 1; fi'
44
+ language: system
45
+ pass_filenames: false
@@ -0,0 +1,313 @@
1
+ > **Technical documentation for extending, integrating, and contributing to OMem.**
2
+ >
3
+ > *Version: 0.0.1 (Pre-Alpha)*
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [System Architecture](#system-architecture)
10
+ 2. [Programmatic Usage (How to use the "bits")](#programmatic-usage-how-to-use-the-bits)
11
+ - [Initialization & Backends](#initialization--backends)
12
+ - [Adding Memories (Types & Importance)](#adding-memories-types--importance)
13
+ - [Recalling Memories (Hybrid RAG)](#recalling-memories-hybrid-rag)
14
+ - [Memory Maintenance (Sleep & TMS)](#memory-maintenance-sleep--tms)
15
+ - [Graph-RAG Explained](#graph-rag-explained)
16
+ - [Agent Integrations (MCP & LangChain)](#agent-integrations-mcp--langchain)
17
+ 3. [Contributor Guide](#contributor-guide)
18
+ - [Environment Setup](#environment-setup)
19
+ - [Branching & PR Workflow](#branching--pr-workflow)
20
+ - [Testing Standard](#testing-standard)
21
+ - [Benchmarking](#benchmarking)
22
+ - [Code Style & Linting](#code-style--linting)
23
+ - [Adding New Backends](#adding-new-backends)
24
+ 4. [CLI Reference](#cli-reference)
25
+ 5. [Context FAQ](#memory-layer-faq--does-it-bloat-context)
26
+
27
+ ---
28
+
29
+ ## System Architecture
30
+
31
+ OMem is organized into highly optimized, modular components:
32
+
33
+ ### 1. Interface Layer (`omem/api.py`)
34
+ Provides the unified entry point for application integration (`class OMem`). It handles request normalization, sensible defaults, and orchestrates interaction between the Brain and Engine layers.
35
+
36
+ ### 2. Retrieval Layer (Rust Core)
37
+ Based in `omem/core/retrieval/` and utilizing the `omem_rust` native extension.
38
+ - **Hybrid Scoring**: SIMD-accelerated ranking combining vector similarity, keyword matching, recency, and importance in a single pass.
39
+ - **Optimized Retrieval**: Built on FAISS HNSW. Thread-safe management of embeddings.
40
+
41
+ ### 3. Logic Layer (The "Brain")
42
+ Based in `omem/core/brain/`. Implementation of core cognitive functions:
43
+ - **Consolidation (`dream.py`)**: Clustering and summarization for memory synthesis.
44
+ - **Truth Maintenance (`tms.py`)**: Detects and resolves conflicting information.
45
+ - **Importance (`importance.py`)**: Heuristic scoring for memory prioritization.
46
+ - **Security (`secrets.py`)**: Automated sensitivity detection.
47
+
48
+ ### 4. Engine Layer
49
+ Based in `omem/core/engine/`. Manages memory lifecycle and state:
50
+ - **Ingestion Pipeline (`add.py`)**: Validates, embeds, classifies, and indexes raw data.
51
+ - **Context Retrieval (`rag.py`)**: Executes complex, multi-signal retrieval strategies.
52
+ - **State Management (`lifecycle.py`)**: Handles archiving, pruning, and snapshotting.
53
+
54
+ ---
55
+
56
+ ## Programmatic Usage (How to use the "bits")
57
+
58
+ If you are building an AI application, you will interact primarily with the `OMem` class in Python.
59
+
60
+ ### Initialization & Backends
61
+
62
+ OMem supports multiple storage backends depending on your deployment needs.
63
+
64
+ ```python
65
+ from omem import OMem
66
+
67
+ # 1. Local SQLite (Default, best for most single-machine agents)
68
+ # Automatically creates ~/.omem/brain.db
69
+ brain = OMem()
70
+
71
+ # 2. In-Memory (Best for unit tests or highly ephemeral tasks)
72
+ test_brain = OMem(backend="memory")
73
+
74
+ # 3. PostgreSQL (Best for production, distributed multi-agent systems)
75
+ pg_brain = OMem(
76
+ backend="postgres",
77
+ db_path="postgresql://user:pass@localhost:5432/omem"
78
+ )
79
+ ```
80
+
81
+ ### Adding Memories (Types & Importance)
82
+
83
+ OMem automatically classifies what you input, but you can explicitly define importance and type to control how the agent remembers it.
84
+
85
+ ```python
86
+ from omem.types import MemoryType
87
+
88
+ # Automatic (OMem detects this is a 'DECISION' and boosts importance based on keywords)
89
+ brain.add("We decided to migrate from REST to GraphQL due to over-fetching.")
90
+
91
+ # Explicit Control
92
+ brain.add(
93
+ "Critical API key rotation policy: Must rotate every 30 days.",
94
+ importance=0.95, # 0.0 to 1.0 (forces it to stay in memory longer)
95
+ mem_type=MemoryType.DECISION # Explicitly categorize the memory
96
+ )
97
+
98
+ # Procedural Tool Snippets (For MCP / Agent tool calling)
99
+ brain.add(
100
+ "To deploy, run 'aws ecs update-service --cluster prod'",
101
+ mem_type=MemoryType.PROCEDURAL
102
+ )
103
+ ```
104
+
105
+ ### Recalling Memories (Hybrid RAG)
106
+
107
+ Retrieval in OMem is not just vector search. It uses 4 signals (Vector + Keyword + Recency + Importance).
108
+
109
+ ```python
110
+ # Standard recall (Returns top 5 matches as a combined string)
111
+ context = brain.recall("What is our API rotation policy?")
112
+
113
+ # Advanced Recall (Returns raw Memory objects for custom formatting)
114
+ raw_memories = brain.recall(
115
+ "deployment steps",
116
+ k=3, # Limit to 3 results
117
+ context_type="PROCEDURAL", # Only look for procedural memories
118
+ time_range="recent" # Only look at recent memories
119
+ )
120
+
121
+ for mem in raw_memories:
122
+ print(f"[{mem.type}] {mem.content} (Score: {mem.score})")
123
+ ```
124
+
125
+ **Debugging Retrieval**: If you want to see *why* OMem picked a memory, use `inspect()`:
126
+ ```python
127
+ for result in brain.inspect("GraphQL"):
128
+ print(result.explain())
129
+ # Output: vector=0.88, keyword=0.45, recency=0.99, importance=1.2x boost -> Final: 0.92
130
+ ```
131
+
132
+ ### Memory Maintenance (Sleep & TMS)
133
+
134
+ Agents, like humans, need to sleep to consolidate memories and remove garbage.
135
+
136
+ ```python
137
+ # Run the full sleep cycle:
138
+ # 1. Deduplicates repetitive memories
139
+ # 2. Forgets low-importance, old memories
140
+ # 3. Reflects on recent events to create high-level insights
141
+ stats = brain.sleep()
142
+ print(f"Forgotten: {stats['forgotten']}, Consolidated: {stats['consolidated']}")
143
+
144
+ # Truth Maintenance System (TMS) - Resolving Conflicts
145
+ brain.add("Python version is 3.9")
146
+ brain.add("Python version is 3.11") # OMem detects this conflicts with 3.9
147
+
148
+ # Explicitly resolve the conflict (archives 3.9, keeps 3.11)
149
+ brain.resolve_conflict("Python version")
150
+ ```
151
+
152
+ ### Graph-RAG Explained
153
+
154
+ When you `add()` a memory, OMem runs a fast NER (Named Entity Recognition) pass to extract entities (e.g., "Python", "GraphQL", "AWS") and builds a graph edge between them.
155
+
156
+ During `recall()`, if `graph_boost=True` (which is default), OMem will:
157
+ 1. Find the top vector matches.
158
+ 2. Look at the entities in those matches.
159
+ 3. Traverse the graph to find *connected* memories that might not share the exact semantic meaning but are highly relevant structurally.
160
+ 4. Inject them into the result set.
161
+
162
+ ### Agent Integrations (MCP & LangChain)
163
+
164
+ **Model Context Protocol (MCP)**
165
+ To expose OMem natively to Claude Desktop or Cursor, simply run the server:
166
+ ```python
167
+ from omem.integrations.mcp_server import serve_mcp
168
+ serve_mcp() # Or use CLI: omem serve
169
+ ```
170
+
171
+ **LangChain Wrapper**
172
+ ```python
173
+ from omem.integrations.langchain import OMemRetriever
174
+ retriever = OMemRetriever(omem_instance=brain)
175
+ # Pass retriever to your LangChain agents
176
+ ```
177
+
178
+ ---
179
+
180
+ ## Contributor Guide
181
+
182
+ We welcome contributions! OMem is built to be fast, typed, and fully tested.
183
+
184
+ ### Environment Setup
185
+
186
+ 1. **Clone & Virtual Env**:
187
+ ```bash
188
+ git clone https://github.com/mohitkumarrajbadi/omem
189
+ cd omem
190
+ python3 -m venv .venv
191
+ source .venv/bin/activate
192
+ ```
193
+ 2. **Install with Dev Dependencies & Rust Extensions**:
194
+ ```bash
195
+ # Note: You must have Rust installed (curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh)
196
+ pip install -e ".[dev]"
197
+ ```
198
+ 3. **Verify**:
199
+ ```bash
200
+ pytest tests/ -v
201
+ ```
202
+
203
+ > **macOS / Anaconda users:** If you experience FAISS/OpenMP crashes, add this to your environment:
204
+ > `export KMP_DUPLICATE_LIB_OK=TRUE`
205
+ > To speed up local runs without network checks: `export HF_HUB_OFFLINE=1`
206
+
207
+ ### Branching & PR Workflow
208
+
209
+ 1. **`dev` (Default)**: All active development happens here. PRs target `dev`.
210
+ 2. **`staging`**: Pre-release integration testing.
211
+ 3. **`main`/`prod`**: Stable releases (`1.0.0`, etc.). Current line is pre-alpha (`0.0.x`).
212
+
213
+ **To contribute:**
214
+ 1. Checkout `dev`: `git checkout dev`
215
+ 2. Create feature branch: `git checkout -b feat/my-new-feature`
216
+ 3. Commit your changes.
217
+ 4. Open a Pull Request targeting the `dev` branch.
218
+
219
+ ### Testing Standard
220
+
221
+ - **Coverage**: All new core logic in `omem/core/` must have unit tests.
222
+ - **Location**: Place tests in the `tests/` directory matching the module structure (e.g., `tests/test_tms.py`).
223
+ - **Command**: Run `pytest tests/` before submitting a PR.
224
+ - **No API Calls**: Tests should mock LLM or external API calls to remain fast and deterministic.
225
+
226
+ ### Benchmarking
227
+
228
+ Because OMem competes directly with vector DBs on speed, performance regressions are strictly monitored.
229
+ If you modify the `rust/` core, `omem/core/retrieval/`, or `omem/core/engine/add.py`, you **must** run the benchmark:
230
+
231
+ ```bash
232
+ python benchmarks/competitor.py
233
+ # Or using the CLI:
234
+ omem benchmark --n 10000
235
+ ```
236
+ Ensure that `add()` operations remain under `5ms` and `RAG` latency remains under `30ms`.
237
+
238
+ ### Code Style & Linting
239
+
240
+ - **Typing**: Strict type hinting is enforced (`def add(text: str, importance: float = 0.5) -> str:`).
241
+ - **Format**: We use standard Python formatting. In the future, we will enforce `ruff`.
242
+ - **Comments**: Explain *why* complex heuristic logic exists, especially in the `brain/` directory.
243
+
244
+ ### Adding New Backends
245
+
246
+ To add a new storage backend (e.g., Redis, MongoDB):
247
+ 1. Create `omem/backends/redis.py`.
248
+ 2. Inherit from `omem.backends.base.StorageBackend`.
249
+ 3. Implement the required interface (`save`, `load`, `delete`, `query`).
250
+ 4. Register the backend in `omem/api.py` inside the `_initialize_backend()` factory.
251
+
252
+ ---
253
+
254
+ ## CLI Reference
255
+
256
+ The `omem` CLI is the primary interface for managing the memory system. Install it with `pip install omem-os`.
257
+
258
+ ### Setup
259
+ | Command | Description |
260
+ |---|---|
261
+ | `omem init` | Initialize memory system at `~/.omem/brain.db` |
262
+ | `omem init --db-path ./custom.db` | Use a custom database path |
263
+ | `omem health` | Health check — exits `0` if OK, `1` if error |
264
+
265
+ ### Writing & Reading
266
+ ```bash
267
+ omem add "content" -i 0.9 -n myproject -t DECISION
268
+ omem search "query" -k 10 -n myproject -c architecture -t recent
269
+ omem list -n myproject -l 50
270
+ omem inspect "query" # Debug retrieval scoring
271
+ ```
272
+
273
+ ### Maintenance & Integrations
274
+ ```bash
275
+ omem maintain # full cycle: compress + reflect + forget + dream
276
+ omem export -f json -o dump.json
277
+ omem load dump.json
278
+ omem serve # start MCP stdio server
279
+ omem dashboard # launch web memory dashboard (port 7900)
280
+ ```
281
+
282
+ ---
283
+
284
+ ## Memory Layer FAQ — Does It Bloat Context?
285
+
286
+ A common concern when connecting OMem to AI agents is:
287
+ > *"Won't injecting memory into every prompt increase context size and add latency?"*
288
+
289
+ **No. OMem is a retrieval layer, not an injection layer.**
290
+
291
+ ### ❌ What people assume (wrong)
292
+ ```
293
+ Every agent turn → dump ALL stored memories into context
294
+ 256 memories × ~100 tokens = 25,600 tokens injected every request
295
+ → Blown context window + high cost + slow responses
296
+ ```
297
+
298
+ ### ✅ What actually happens
299
+ ```
300
+ Every agent turn → semantic search returns only TOP 3–5 relevant memories
301
+ 256 memories stored, ~5 retrieved → ~200–500 tokens injected
302
+ → Lean, precise, always relevant context
303
+ ```
304
+
305
+ ### Direct comparison
306
+ | | Without OMem | With OMem |
307
+ |---|---|---|
308
+ | Context per turn | Full conversation history (grows unboundedly) | 3–5 recalled memories (~300 tokens) |
309
+ | Cross-session memory | ❌ Starts from zero each session | ✅ Persistent across sessions, projects, restarts |
310
+ | Token cost | High — re-reads everything | Low — retrieves only what's relevant |
311
+ | Latency added | 0ms (no memory) | <1ms (FAISS search) + ~10ms (embedding) |
312
+
313
+ **Connecting OMem to an agent makes it smarter with *less* context, not slower with more.**