holographic-memory-engine 1.0.2__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.
- holographic_memory_engine-1.0.2/PKG-INFO +195 -0
- holographic_memory_engine-1.0.2/README.md +151 -0
- holographic_memory_engine-1.0.2/pyproject.toml +0 -0
- holographic_memory_engine-1.0.2/setup.cfg +4 -0
- holographic_memory_engine-1.0.2/setup.py +44 -0
- holographic_memory_engine-1.0.2/src/holographic_memory_engine.egg-info/PKG-INFO +195 -0
- holographic_memory_engine-1.0.2/src/holographic_memory_engine.egg-info/SOURCES.txt +11 -0
- holographic_memory_engine-1.0.2/src/holographic_memory_engine.egg-info/dependency_links.txt +1 -0
- holographic_memory_engine-1.0.2/src/holographic_memory_engine.egg-info/not-zip-safe +1 -0
- holographic_memory_engine-1.0.2/src/holographic_memory_engine.egg-info/requires.txt +12 -0
- holographic_memory_engine-1.0.2/src/holographic_memory_engine.egg-info/top_level.txt +1 -0
- holographic_memory_engine-1.0.2/test/test_engine.py +30 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: holographic-memory-engine
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: A universal phase-space memory engine that retrieves knowledge via holographic interference instead of vector similarity search.
|
|
5
|
+
Home-page: https://github.com/Luckyy0311
|
|
6
|
+
Author: Abdul Mofique Siddiqui
|
|
7
|
+
Author-email: mofique7860@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: holographic-memory,rag,vector-search,ai,retrieval
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: numpy>=1.21
|
|
24
|
+
Provides-Extra: gpu
|
|
25
|
+
Requires-Dist: cupy>=12.0; extra == "gpu"
|
|
26
|
+
Provides-Extra: neural
|
|
27
|
+
Requires-Dist: sentence-transformers>=2.2; extra == "neural"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
30
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
31
|
+
Requires-Dist: twine>=4.0; extra == "dev"
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: author-email
|
|
34
|
+
Dynamic: classifier
|
|
35
|
+
Dynamic: description
|
|
36
|
+
Dynamic: description-content-type
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: keywords
|
|
39
|
+
Dynamic: license
|
|
40
|
+
Dynamic: provides-extra
|
|
41
|
+
Dynamic: requires-dist
|
|
42
|
+
Dynamic: requires-python
|
|
43
|
+
Dynamic: summary
|
|
44
|
+
|
|
45
|
+
# holographic-memory-engine
|
|
46
|
+
|
|
47
|
+
A universal phase-space memory engine that retrieves knowledge via **holographic
|
|
48
|
+
interference** instead of vector similarity search.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
[](https://opensource.org/licenses/MIT)
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Why?
|
|
56
|
+
|
|
57
|
+
Classic RAG retrieves text chunks by cosine similarity and stuffs them into a
|
|
58
|
+
prompt. This returns **passages**, not answers, and pollutes the context window.
|
|
59
|
+
|
|
60
|
+
`holographic-memory` binds `key -> value` pairs into complex phase vectors and
|
|
61
|
+
retrieves by **constructive / destructive wave interference**. The result is the
|
|
62
|
+
exact value, directly, with no chunk stuffing.
|
|
63
|
+
|
|
64
|
+
| Feature | Classic RAG | holographic-memory |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| Retrieval signal | Cosine similarity | Phase interference |
|
|
67
|
+
| Returns | Text chunk | Exact value |
|
|
68
|
+
| Context pollution | High | None |
|
|
69
|
+
| Answer verbosity | High | Minimal |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install holographic-memory
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Optional extras:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# GPU acceleration via CuPy
|
|
83
|
+
pip install holographic-memory[gpu]
|
|
84
|
+
|
|
85
|
+
# Neural (sentence-transformers) encoder
|
|
86
|
+
pip install holographic-memory[neural]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Quick Start
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from holographic import HolographicEngine, HashPhaseEncoder
|
|
95
|
+
|
|
96
|
+
engine = HolographicEngine(encoder=HashPhaseEncoder(dim=2048))
|
|
97
|
+
|
|
98
|
+
engine.add("capital France", "Paris")
|
|
99
|
+
engine.add("capital Japan", "Tokyo")
|
|
100
|
+
engine.add("ceo Tesla", "Elon Musk")
|
|
101
|
+
engine.build()
|
|
102
|
+
|
|
103
|
+
print(engine.ask("What is the capital of France?")["answer"])
|
|
104
|
+
# -> Paris
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Use a Neural Encoder
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from holographic import HolographicEngine, NeuralPhaseEncoder
|
|
113
|
+
|
|
114
|
+
engine = HolographicEngine(encoder=NeuralPhaseEncoder(dim=2048))
|
|
115
|
+
# ... same API
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Custom Encoder
|
|
119
|
+
|
|
120
|
+
Any object with a `dim` attribute and an `encode(text) -> complex ndarray`
|
|
121
|
+
method works:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import numpy as np
|
|
125
|
+
from holographic import HolographicEngine
|
|
126
|
+
|
|
127
|
+
class MyEncoder:
|
|
128
|
+
dim = 2048
|
|
129
|
+
def encode(self, text: str) -> np.ndarray:
|
|
130
|
+
# your logic; return complex64 vector of shape (dim,)
|
|
131
|
+
...
|
|
132
|
+
|
|
133
|
+
engine = HolographicEngine(encoder=MyEncoder())
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Ingest a Whole Document
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from holographic import HolographicEngine, HashPhaseEncoder, ingest_text
|
|
142
|
+
|
|
143
|
+
engine = HolographicEngine(encoder=HashPhaseEncoder(dim=2048))
|
|
144
|
+
ingest_text(engine, open("handbook.txt").read(), source="handbook")
|
|
145
|
+
engine.build()
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Save / Load
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from holographic import save_engine, load_engine
|
|
152
|
+
|
|
153
|
+
save_engine(engine, "memory.json")
|
|
154
|
+
load_engine(engine, "memory.json")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Configuration
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from holographic import HolographicConfig
|
|
163
|
+
|
|
164
|
+
config = HolographicConfig(
|
|
165
|
+
dim=4096, # vector dimensionality
|
|
166
|
+
shard_capacity=0, # 0 = single large shard
|
|
167
|
+
default_top_k=5,
|
|
168
|
+
score_threshold=0.0,
|
|
169
|
+
margin_ratio=1.02,
|
|
170
|
+
use_gpu=False,
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## How It Works
|
|
177
|
+
|
|
178
|
+
1. **Bind** — `key` and `value` are encoded to constant-modulus complex vectors, then bound via element-wise multiplication: `key * value`.
|
|
179
|
+
2. **Superpose** — all bindings are summed into a single memory vector.
|
|
180
|
+
3. **Retrieve** — the query is multiplied by the conjugate of the memory. Matching keys resonate (constructive interference) and surface their bound values; non-matches cancel out (destructive interference).
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Running the Benchmark
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
pip install -e .
|
|
188
|
+
python examples/evaluate.py
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# holographic-memory-engine
|
|
2
|
+
|
|
3
|
+
A universal phase-space memory engine that retrieves knowledge via **holographic
|
|
4
|
+
interference** instead of vector similarity search.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Why?
|
|
12
|
+
|
|
13
|
+
Classic RAG retrieves text chunks by cosine similarity and stuffs them into a
|
|
14
|
+
prompt. This returns **passages**, not answers, and pollutes the context window.
|
|
15
|
+
|
|
16
|
+
`holographic-memory` binds `key -> value` pairs into complex phase vectors and
|
|
17
|
+
retrieves by **constructive / destructive wave interference**. The result is the
|
|
18
|
+
exact value, directly, with no chunk stuffing.
|
|
19
|
+
|
|
20
|
+
| Feature | Classic RAG | holographic-memory |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| Retrieval signal | Cosine similarity | Phase interference |
|
|
23
|
+
| Returns | Text chunk | Exact value |
|
|
24
|
+
| Context pollution | High | None |
|
|
25
|
+
| Answer verbosity | High | Minimal |
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install holographic-memory
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Optional extras:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# GPU acceleration via CuPy
|
|
39
|
+
pip install holographic-memory[gpu]
|
|
40
|
+
|
|
41
|
+
# Neural (sentence-transformers) encoder
|
|
42
|
+
pip install holographic-memory[neural]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from holographic import HolographicEngine, HashPhaseEncoder
|
|
51
|
+
|
|
52
|
+
engine = HolographicEngine(encoder=HashPhaseEncoder(dim=2048))
|
|
53
|
+
|
|
54
|
+
engine.add("capital France", "Paris")
|
|
55
|
+
engine.add("capital Japan", "Tokyo")
|
|
56
|
+
engine.add("ceo Tesla", "Elon Musk")
|
|
57
|
+
engine.build()
|
|
58
|
+
|
|
59
|
+
print(engine.ask("What is the capital of France?")["answer"])
|
|
60
|
+
# -> Paris
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Use a Neural Encoder
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from holographic import HolographicEngine, NeuralPhaseEncoder
|
|
69
|
+
|
|
70
|
+
engine = HolographicEngine(encoder=NeuralPhaseEncoder(dim=2048))
|
|
71
|
+
# ... same API
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Custom Encoder
|
|
75
|
+
|
|
76
|
+
Any object with a `dim` attribute and an `encode(text) -> complex ndarray`
|
|
77
|
+
method works:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import numpy as np
|
|
81
|
+
from holographic import HolographicEngine
|
|
82
|
+
|
|
83
|
+
class MyEncoder:
|
|
84
|
+
dim = 2048
|
|
85
|
+
def encode(self, text: str) -> np.ndarray:
|
|
86
|
+
# your logic; return complex64 vector of shape (dim,)
|
|
87
|
+
...
|
|
88
|
+
|
|
89
|
+
engine = HolographicEngine(encoder=MyEncoder())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Ingest a Whole Document
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from holographic import HolographicEngine, HashPhaseEncoder, ingest_text
|
|
98
|
+
|
|
99
|
+
engine = HolographicEngine(encoder=HashPhaseEncoder(dim=2048))
|
|
100
|
+
ingest_text(engine, open("handbook.txt").read(), source="handbook")
|
|
101
|
+
engine.build()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Save / Load
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from holographic import save_engine, load_engine
|
|
108
|
+
|
|
109
|
+
save_engine(engine, "memory.json")
|
|
110
|
+
load_engine(engine, "memory.json")
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Configuration
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from holographic import HolographicConfig
|
|
119
|
+
|
|
120
|
+
config = HolographicConfig(
|
|
121
|
+
dim=4096, # vector dimensionality
|
|
122
|
+
shard_capacity=0, # 0 = single large shard
|
|
123
|
+
default_top_k=5,
|
|
124
|
+
score_threshold=0.0,
|
|
125
|
+
margin_ratio=1.02,
|
|
126
|
+
use_gpu=False,
|
|
127
|
+
)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## How It Works
|
|
133
|
+
|
|
134
|
+
1. **Bind** — `key` and `value` are encoded to constant-modulus complex vectors, then bound via element-wise multiplication: `key * value`.
|
|
135
|
+
2. **Superpose** — all bindings are summed into a single memory vector.
|
|
136
|
+
3. **Retrieve** — the query is multiplied by the conjugate of the memory. Matching keys resonate (constructive interference) and surface their bound values; non-matches cancel out (destructive interference).
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Running the Benchmark
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
pip install -e .
|
|
144
|
+
python examples/evaluate.py
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT — see [LICENSE](LICENSE).
|
|
File without changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from setuptools import setup, find_packages
|
|
3
|
+
|
|
4
|
+
this_directory = Path(__file__).parent
|
|
5
|
+
long_description = (this_directory / "README.md").read_text(encoding="utf-8")
|
|
6
|
+
|
|
7
|
+
setup(
|
|
8
|
+
name='holographic-memory-engine',
|
|
9
|
+
version='1.0.2',
|
|
10
|
+
author='Abdul Mofique Siddiqui',
|
|
11
|
+
author_email='mofique7860@gmail.com',
|
|
12
|
+
description='A universal phase-space memory engine that retrieves knowledge via holographic interference instead of vector similarity search.',
|
|
13
|
+
long_description=long_description,
|
|
14
|
+
long_description_content_type='text/markdown',
|
|
15
|
+
url='https://github.com/Luckyy0311',
|
|
16
|
+
license='MIT',
|
|
17
|
+
package_dir={"": "src"},
|
|
18
|
+
packages=find_packages(where="src"),
|
|
19
|
+
classifiers=[
|
|
20
|
+
'Development Status :: 4 - Beta',
|
|
21
|
+
'Intended Audience :: Science/Research',
|
|
22
|
+
'Intended Audience :: Developers',
|
|
23
|
+
'License :: OSI Approved :: MIT License',
|
|
24
|
+
'Programming Language :: Python :: 3',
|
|
25
|
+
'Programming Language :: Python :: 3.9',
|
|
26
|
+
'Programming Language :: Python :: 3.10',
|
|
27
|
+
'Programming Language :: Python :: 3.11',
|
|
28
|
+
'Programming Language :: Python :: 3.12',
|
|
29
|
+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
|
|
30
|
+
'Topic :: Software Development :: Libraries :: Python Modules',
|
|
31
|
+
],
|
|
32
|
+
keywords=["holographic-memory", "rag", "vector-search", "ai", "retrieval"],
|
|
33
|
+
python_requires='>=3.9',
|
|
34
|
+
install_requires=[
|
|
35
|
+
'numpy>=1.21',
|
|
36
|
+
],
|
|
37
|
+
extras_require={
|
|
38
|
+
"gpu": ["cupy>=12.0"],
|
|
39
|
+
"neural": ["sentence-transformers>=2.2"],
|
|
40
|
+
"dev": ["pytest>=7.0", "build>=1.0", "twine>=4.0"],
|
|
41
|
+
},
|
|
42
|
+
include_package_data=True,
|
|
43
|
+
zip_safe=False,
|
|
44
|
+
)
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: holographic-memory-engine
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: A universal phase-space memory engine that retrieves knowledge via holographic interference instead of vector similarity search.
|
|
5
|
+
Home-page: https://github.com/Luckyy0311
|
|
6
|
+
Author: Abdul Mofique Siddiqui
|
|
7
|
+
Author-email: mofique7860@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: holographic-memory,rag,vector-search,ai,retrieval
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: numpy>=1.21
|
|
24
|
+
Provides-Extra: gpu
|
|
25
|
+
Requires-Dist: cupy>=12.0; extra == "gpu"
|
|
26
|
+
Provides-Extra: neural
|
|
27
|
+
Requires-Dist: sentence-transformers>=2.2; extra == "neural"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
30
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
31
|
+
Requires-Dist: twine>=4.0; extra == "dev"
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: author-email
|
|
34
|
+
Dynamic: classifier
|
|
35
|
+
Dynamic: description
|
|
36
|
+
Dynamic: description-content-type
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: keywords
|
|
39
|
+
Dynamic: license
|
|
40
|
+
Dynamic: provides-extra
|
|
41
|
+
Dynamic: requires-dist
|
|
42
|
+
Dynamic: requires-python
|
|
43
|
+
Dynamic: summary
|
|
44
|
+
|
|
45
|
+
# holographic-memory-engine
|
|
46
|
+
|
|
47
|
+
A universal phase-space memory engine that retrieves knowledge via **holographic
|
|
48
|
+
interference** instead of vector similarity search.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
[](https://opensource.org/licenses/MIT)
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Why?
|
|
56
|
+
|
|
57
|
+
Classic RAG retrieves text chunks by cosine similarity and stuffs them into a
|
|
58
|
+
prompt. This returns **passages**, not answers, and pollutes the context window.
|
|
59
|
+
|
|
60
|
+
`holographic-memory` binds `key -> value` pairs into complex phase vectors and
|
|
61
|
+
retrieves by **constructive / destructive wave interference**. The result is the
|
|
62
|
+
exact value, directly, with no chunk stuffing.
|
|
63
|
+
|
|
64
|
+
| Feature | Classic RAG | holographic-memory |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| Retrieval signal | Cosine similarity | Phase interference |
|
|
67
|
+
| Returns | Text chunk | Exact value |
|
|
68
|
+
| Context pollution | High | None |
|
|
69
|
+
| Answer verbosity | High | Minimal |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install holographic-memory
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Optional extras:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# GPU acceleration via CuPy
|
|
83
|
+
pip install holographic-memory[gpu]
|
|
84
|
+
|
|
85
|
+
# Neural (sentence-transformers) encoder
|
|
86
|
+
pip install holographic-memory[neural]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Quick Start
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from holographic import HolographicEngine, HashPhaseEncoder
|
|
95
|
+
|
|
96
|
+
engine = HolographicEngine(encoder=HashPhaseEncoder(dim=2048))
|
|
97
|
+
|
|
98
|
+
engine.add("capital France", "Paris")
|
|
99
|
+
engine.add("capital Japan", "Tokyo")
|
|
100
|
+
engine.add("ceo Tesla", "Elon Musk")
|
|
101
|
+
engine.build()
|
|
102
|
+
|
|
103
|
+
print(engine.ask("What is the capital of France?")["answer"])
|
|
104
|
+
# -> Paris
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Use a Neural Encoder
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from holographic import HolographicEngine, NeuralPhaseEncoder
|
|
113
|
+
|
|
114
|
+
engine = HolographicEngine(encoder=NeuralPhaseEncoder(dim=2048))
|
|
115
|
+
# ... same API
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Custom Encoder
|
|
119
|
+
|
|
120
|
+
Any object with a `dim` attribute and an `encode(text) -> complex ndarray`
|
|
121
|
+
method works:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import numpy as np
|
|
125
|
+
from holographic import HolographicEngine
|
|
126
|
+
|
|
127
|
+
class MyEncoder:
|
|
128
|
+
dim = 2048
|
|
129
|
+
def encode(self, text: str) -> np.ndarray:
|
|
130
|
+
# your logic; return complex64 vector of shape (dim,)
|
|
131
|
+
...
|
|
132
|
+
|
|
133
|
+
engine = HolographicEngine(encoder=MyEncoder())
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Ingest a Whole Document
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from holographic import HolographicEngine, HashPhaseEncoder, ingest_text
|
|
142
|
+
|
|
143
|
+
engine = HolographicEngine(encoder=HashPhaseEncoder(dim=2048))
|
|
144
|
+
ingest_text(engine, open("handbook.txt").read(), source="handbook")
|
|
145
|
+
engine.build()
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Save / Load
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from holographic import save_engine, load_engine
|
|
152
|
+
|
|
153
|
+
save_engine(engine, "memory.json")
|
|
154
|
+
load_engine(engine, "memory.json")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Configuration
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from holographic import HolographicConfig
|
|
163
|
+
|
|
164
|
+
config = HolographicConfig(
|
|
165
|
+
dim=4096, # vector dimensionality
|
|
166
|
+
shard_capacity=0, # 0 = single large shard
|
|
167
|
+
default_top_k=5,
|
|
168
|
+
score_threshold=0.0,
|
|
169
|
+
margin_ratio=1.02,
|
|
170
|
+
use_gpu=False,
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## How It Works
|
|
177
|
+
|
|
178
|
+
1. **Bind** — `key` and `value` are encoded to constant-modulus complex vectors, then bound via element-wise multiplication: `key * value`.
|
|
179
|
+
2. **Superpose** — all bindings are summed into a single memory vector.
|
|
180
|
+
3. **Retrieve** — the query is multiplied by the conjugate of the memory. Matching keys resonate (constructive interference) and surface their bound values; non-matches cancel out (destructive interference).
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Running the Benchmark
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
pip install -e .
|
|
188
|
+
python examples/evaluate.py
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.cfg
|
|
4
|
+
setup.py
|
|
5
|
+
src/holographic_memory_engine.egg-info/PKG-INFO
|
|
6
|
+
src/holographic_memory_engine.egg-info/SOURCES.txt
|
|
7
|
+
src/holographic_memory_engine.egg-info/dependency_links.txt
|
|
8
|
+
src/holographic_memory_engine.egg-info/not-zip-safe
|
|
9
|
+
src/holographic_memory_engine.egg-info/requires.txt
|
|
10
|
+
src/holographic_memory_engine.egg-info/top_level.txt
|
|
11
|
+
test/test_engine.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Unit tests for the holographic engine."""
|
|
2
|
+
import tempfile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from holographic import HolographicEngine, HashPhaseEncoder, HolographicConfig
|
|
5
|
+
|
|
6
|
+
def make_engine(dim=512):
|
|
7
|
+
config = HolographicConfig(dim=dim)
|
|
8
|
+
return HolographicEngine(encoder=HashPhaseEncoder(dim=dim), config=config)
|
|
9
|
+
|
|
10
|
+
def test_basic_add_and_ask():
|
|
11
|
+
engine = make_engine()
|
|
12
|
+
engine.add("capital France", "Paris")
|
|
13
|
+
engine.add("capital Japan", "Tokyo")
|
|
14
|
+
engine.build()
|
|
15
|
+
assert engine.ask("What is the capital of France?")["answer"] == "Paris"
|
|
16
|
+
|
|
17
|
+
def test_save_and_load():
|
|
18
|
+
engine = make_engine()
|
|
19
|
+
engine.add("capital France", "Paris")
|
|
20
|
+
engine.build()
|
|
21
|
+
|
|
22
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
23
|
+
path = str(Path(tmp) / "state.json")
|
|
24
|
+
|
|
25
|
+
# Using the new clean methods
|
|
26
|
+
engine.save(path)
|
|
27
|
+
|
|
28
|
+
engine2 = make_engine()
|
|
29
|
+
engine2.load(path)
|
|
30
|
+
assert engine2.ask("capital France")["answer"] == "Paris"
|