cognee-community-vector-adapter-redis 0.0.1__tar.gz → 0.1.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.
- {cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/.gitignore +7 -0
- {cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/PKG-INFO +102 -72
- {cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/README.md +98 -70
- {cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/__init__.py +1 -1
- {cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/cognee_community_vector_adapter_redis/redis_adapter.py +184 -146
- {cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/examples/example.py +18 -12
- cognee_community_vector_adapter_redis-0.1.0/poetry.lock +4968 -0
- {cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/pyproject.toml +4 -2
- cognee_community_vector_adapter_redis-0.1.0/tests/test_redis.py +220 -0
- cognee_community_vector_adapter_redis-0.1.0/uv.lock +3306 -0
- cognee_community_vector_adapter_redis-0.0.1/uv.lock +0 -3325
- {cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/cognee_community_vector_adapter_redis/__init__.py +0 -0
- {cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/cognee_community_vector_adapter_redis/register.py +0 -0
{cognee_community_vector_adapter_redis-0.0.1 → cognee_community_vector_adapter_redis-0.1.0}/PKG-INFO
RENAMED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cognee-community-vector-adapter-redis
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.1.0
|
|
4
4
|
Summary: Redis vector database adapter for cognee
|
|
5
5
|
Requires-Python: <=3.13,>=3.11
|
|
6
|
-
Requires-Dist: cognee
|
|
6
|
+
Requires-Dist: cognee==0.5.2
|
|
7
|
+
Requires-Dist: instructor>=1.11
|
|
7
8
|
Requires-Dist: redisvl<=1.0.0,>=0.6.0
|
|
9
|
+
Requires-Dist: starlette>=0.48.0
|
|
8
10
|
Description-Content-Type: text/markdown
|
|
9
11
|
|
|
10
12
|
<div align="center" dir="auto">
|
|
@@ -17,7 +19,7 @@ Description-Content-Type: text/markdown
|
|
|
17
19
|
<br />
|
|
18
20
|
|
|
19
21
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
20
|
-

|
|
21
23
|
|
|
22
24
|
[](https://github.com/redis/redis-vl-python)
|
|
23
25
|
|
|
@@ -44,10 +46,19 @@ Description-Content-Type: text/markdown
|
|
|
44
46
|
|
|
45
47
|
## Installation
|
|
46
48
|
|
|
49
|
+
If published, the package can be simply installed via pip:
|
|
50
|
+
|
|
47
51
|
```bash
|
|
48
52
|
pip install cognee-community-vector-adapter-redis
|
|
49
53
|
```
|
|
50
54
|
|
|
55
|
+
In case it is not published yet, you can use poetry to locally build the adapter package:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install poetry
|
|
59
|
+
poetry install # run this command in the directory containing the pyproject.toml file
|
|
60
|
+
```
|
|
61
|
+
|
|
51
62
|
## Prerequisites
|
|
52
63
|
|
|
53
64
|
You need a Redis instance with the Redis Search module enabled. You can use:
|
|
@@ -71,96 +82,115 @@ uv run examples/example.py
|
|
|
71
82
|
## Usage
|
|
72
83
|
|
|
73
84
|
```python
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
import os
|
|
86
|
+
import asyncio
|
|
87
|
+
from cognee import config, prune, add, cognify, search, SearchType
|
|
88
|
+
|
|
89
|
+
# Import the register module to enable Redis support
|
|
90
|
+
from cognee_community_vector_adapter_redis import register
|
|
91
|
+
|
|
92
|
+
async def main():
|
|
93
|
+
# Configure Redis as vector database
|
|
94
|
+
config.set_vector_db_config({
|
|
95
|
+
"vector_db_provider": "redis",
|
|
96
|
+
"vector_db_url": os.getenv("VECTOR_DB_URL", "redis://localhost:6379"),
|
|
97
|
+
"vector_db_key": os.getenv("VECTOR_DB_KEY", "your-api-key"), # Optional
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
# Optional: Clean previous data
|
|
101
|
+
await prune.prune_data()
|
|
102
|
+
await prune.prune_system()
|
|
103
|
+
|
|
104
|
+
# Add your content
|
|
105
|
+
await add("""
|
|
106
|
+
Natural language processing (NLP) is an interdisciplinary
|
|
107
|
+
subfield of computer science and information retrieval.
|
|
108
|
+
""")
|
|
109
|
+
|
|
110
|
+
# Process with cognee
|
|
111
|
+
await cognify()
|
|
112
|
+
|
|
113
|
+
# Search
|
|
114
|
+
search_results = await search(
|
|
115
|
+
query_type=SearchType.GRAPH_COMPLETION,
|
|
116
|
+
query_text="Tell me about NLP"
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
for result in search_results:
|
|
120
|
+
print("Search result:", result)
|
|
121
|
+
|
|
122
|
+
if __name__ == "__main__":
|
|
123
|
+
asyncio.run(main())
|
|
124
|
+
```
|
|
89
125
|
|
|
90
|
-
|
|
91
|
-
await redis_adapter.create_collection("my_collection")
|
|
126
|
+
## Configuration
|
|
92
127
|
|
|
93
|
-
|
|
94
|
-
from cognee.infrastructure.engine import DataPoint
|
|
128
|
+
Configure Redis as your vector database in cognee:
|
|
95
129
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
]
|
|
130
|
+
- `vector_db_provider`: Set to "redis"
|
|
131
|
+
- `vector_db_url`: Redis connection URL (e.g., "redis://localhost:6379")
|
|
132
|
+
- `vector_db_key`: Optional API key parameter (for compatibility, not used by Redis)
|
|
100
133
|
|
|
101
|
-
|
|
134
|
+
### Environment Variables
|
|
102
135
|
|
|
103
|
-
|
|
104
|
-
results = await redis_adapter.search(
|
|
105
|
-
collection_name="my_collection",
|
|
106
|
-
query_text="Hello Redis",
|
|
107
|
-
limit=10
|
|
108
|
-
)
|
|
136
|
+
Set the following environment variables or pass them directly in the config:
|
|
109
137
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
query_vector=query_vector[0],
|
|
115
|
-
limit=10,
|
|
116
|
-
with_vector=True # Include vectors in results
|
|
117
|
-
)
|
|
138
|
+
```bash
|
|
139
|
+
export VECTOR_DB_URL="redis://localhost:6379"
|
|
140
|
+
export VECTOR_DB_KEY="optional-key" # Not used by Redis
|
|
141
|
+
```
|
|
118
142
|
|
|
119
|
-
|
|
120
|
-
results = await redis_adapter.batch_search(
|
|
121
|
-
collection_name="my_collection",
|
|
122
|
-
query_texts=["query1", "query2"],
|
|
123
|
-
limit=5
|
|
124
|
-
)
|
|
143
|
+
### Connection URL Examples
|
|
125
144
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
145
|
+
```python
|
|
146
|
+
# Local Redis
|
|
147
|
+
config.set_vector_db_config({
|
|
148
|
+
"vector_db_provider": "redis",
|
|
149
|
+
"vector_db_url": "redis://localhost:6379"
|
|
150
|
+
})
|
|
131
151
|
|
|
132
|
-
#
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
)
|
|
152
|
+
# Redis with authentication
|
|
153
|
+
config.set_vector_db_config({
|
|
154
|
+
"vector_db_provider": "redis",
|
|
155
|
+
"vector_db_url": "redis://user:password@localhost:6379"
|
|
156
|
+
})
|
|
137
157
|
|
|
138
|
-
#
|
|
139
|
-
|
|
158
|
+
# Redis with SSL
|
|
159
|
+
config.set_vector_db_config({
|
|
160
|
+
"vector_db_provider": "redis",
|
|
161
|
+
"vector_db_url": "rediss://localhost:6380"
|
|
162
|
+
})
|
|
140
163
|
```
|
|
141
164
|
|
|
142
|
-
##
|
|
165
|
+
## Requirements
|
|
143
166
|
|
|
144
|
-
|
|
167
|
+
- Python >= 3.11, <= 3.13
|
|
168
|
+
- redisvl >= 0.6.0, <= 1.0.0
|
|
169
|
+
- cognee >= 0.2.0.dev0
|
|
145
170
|
|
|
146
|
-
|
|
147
|
-
- `embedding_engine`: The `EmbeddingEngine` to use for text vectorization (required)
|
|
148
|
-
- `api_key`: Optional API key parameter (not used for Redis but part of the interface)
|
|
171
|
+
## Advanced Usage
|
|
149
172
|
|
|
150
|
-
|
|
173
|
+
For direct adapter usage (advanced users only):
|
|
151
174
|
|
|
152
175
|
```python
|
|
153
|
-
|
|
154
|
-
|
|
176
|
+
from cognee.infrastructure.databases.vector.embeddings.EmbeddingEngine import EmbeddingEngine
|
|
177
|
+
from cognee_community_vector_adapter_redis import RedisAdapter
|
|
178
|
+
from cognee.infrastructure.engine import DataPoint
|
|
155
179
|
|
|
156
|
-
#
|
|
157
|
-
|
|
180
|
+
# Initialize embedding engine and adapter
|
|
181
|
+
embedding_engine = EmbeddingEngine(model="your-model")
|
|
182
|
+
redis_adapter = RedisAdapter(
|
|
183
|
+
url="redis://localhost:6379",
|
|
184
|
+
embedding_engine=embedding_engine
|
|
185
|
+
)
|
|
158
186
|
|
|
159
|
-
#
|
|
160
|
-
redis_adapter
|
|
187
|
+
# Direct adapter operations
|
|
188
|
+
await redis_adapter.create_collection("my_collection")
|
|
189
|
+
data_points = [DataPoint(id="1", text="Hello", metadata={"index_fields": ["text"]})]
|
|
190
|
+
await redis_adapter.create_data_points("my_collection", data_points)
|
|
191
|
+
results = await redis_adapter.search("my_collection", query_text="Hello", limit=10)
|
|
161
192
|
```
|
|
162
193
|
|
|
163
|
-
|
|
164
194
|
## Error Handling
|
|
165
195
|
|
|
166
196
|
The adapter includes comprehensive error handling:
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<br />
|
|
9
9
|
|
|
10
10
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
11
|
-

|
|
12
12
|
|
|
13
13
|
[](https://github.com/redis/redis-vl-python)
|
|
14
14
|
|
|
@@ -35,10 +35,19 @@
|
|
|
35
35
|
|
|
36
36
|
## Installation
|
|
37
37
|
|
|
38
|
+
If published, the package can be simply installed via pip:
|
|
39
|
+
|
|
38
40
|
```bash
|
|
39
41
|
pip install cognee-community-vector-adapter-redis
|
|
40
42
|
```
|
|
41
43
|
|
|
44
|
+
In case it is not published yet, you can use poetry to locally build the adapter package:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install poetry
|
|
48
|
+
poetry install # run this command in the directory containing the pyproject.toml file
|
|
49
|
+
```
|
|
50
|
+
|
|
42
51
|
## Prerequisites
|
|
43
52
|
|
|
44
53
|
You need a Redis instance with the Redis Search module enabled. You can use:
|
|
@@ -62,96 +71,115 @@ uv run examples/example.py
|
|
|
62
71
|
## Usage
|
|
63
72
|
|
|
64
73
|
```python
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
import os
|
|
75
|
+
import asyncio
|
|
76
|
+
from cognee import config, prune, add, cognify, search, SearchType
|
|
77
|
+
|
|
78
|
+
# Import the register module to enable Redis support
|
|
79
|
+
from cognee_community_vector_adapter_redis import register
|
|
80
|
+
|
|
81
|
+
async def main():
|
|
82
|
+
# Configure Redis as vector database
|
|
83
|
+
config.set_vector_db_config({
|
|
84
|
+
"vector_db_provider": "redis",
|
|
85
|
+
"vector_db_url": os.getenv("VECTOR_DB_URL", "redis://localhost:6379"),
|
|
86
|
+
"vector_db_key": os.getenv("VECTOR_DB_KEY", "your-api-key"), # Optional
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
# Optional: Clean previous data
|
|
90
|
+
await prune.prune_data()
|
|
91
|
+
await prune.prune_system()
|
|
92
|
+
|
|
93
|
+
# Add your content
|
|
94
|
+
await add("""
|
|
95
|
+
Natural language processing (NLP) is an interdisciplinary
|
|
96
|
+
subfield of computer science and information retrieval.
|
|
97
|
+
""")
|
|
98
|
+
|
|
99
|
+
# Process with cognee
|
|
100
|
+
await cognify()
|
|
101
|
+
|
|
102
|
+
# Search
|
|
103
|
+
search_results = await search(
|
|
104
|
+
query_type=SearchType.GRAPH_COMPLETION,
|
|
105
|
+
query_text="Tell me about NLP"
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
for result in search_results:
|
|
109
|
+
print("Search result:", result)
|
|
110
|
+
|
|
111
|
+
if __name__ == "__main__":
|
|
112
|
+
asyncio.run(main())
|
|
113
|
+
```
|
|
80
114
|
|
|
81
|
-
|
|
82
|
-
await redis_adapter.create_collection("my_collection")
|
|
115
|
+
## Configuration
|
|
83
116
|
|
|
84
|
-
|
|
85
|
-
from cognee.infrastructure.engine import DataPoint
|
|
117
|
+
Configure Redis as your vector database in cognee:
|
|
86
118
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
]
|
|
119
|
+
- `vector_db_provider`: Set to "redis"
|
|
120
|
+
- `vector_db_url`: Redis connection URL (e.g., "redis://localhost:6379")
|
|
121
|
+
- `vector_db_key`: Optional API key parameter (for compatibility, not used by Redis)
|
|
91
122
|
|
|
92
|
-
|
|
123
|
+
### Environment Variables
|
|
93
124
|
|
|
94
|
-
|
|
95
|
-
results = await redis_adapter.search(
|
|
96
|
-
collection_name="my_collection",
|
|
97
|
-
query_text="Hello Redis",
|
|
98
|
-
limit=10
|
|
99
|
-
)
|
|
125
|
+
Set the following environment variables or pass them directly in the config:
|
|
100
126
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
query_vector=query_vector[0],
|
|
106
|
-
limit=10,
|
|
107
|
-
with_vector=True # Include vectors in results
|
|
108
|
-
)
|
|
127
|
+
```bash
|
|
128
|
+
export VECTOR_DB_URL="redis://localhost:6379"
|
|
129
|
+
export VECTOR_DB_KEY="optional-key" # Not used by Redis
|
|
130
|
+
```
|
|
109
131
|
|
|
110
|
-
|
|
111
|
-
results = await redis_adapter.batch_search(
|
|
112
|
-
collection_name="my_collection",
|
|
113
|
-
query_texts=["query1", "query2"],
|
|
114
|
-
limit=5
|
|
115
|
-
)
|
|
132
|
+
### Connection URL Examples
|
|
116
133
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
134
|
+
```python
|
|
135
|
+
# Local Redis
|
|
136
|
+
config.set_vector_db_config({
|
|
137
|
+
"vector_db_provider": "redis",
|
|
138
|
+
"vector_db_url": "redis://localhost:6379"
|
|
139
|
+
})
|
|
122
140
|
|
|
123
|
-
#
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
)
|
|
141
|
+
# Redis with authentication
|
|
142
|
+
config.set_vector_db_config({
|
|
143
|
+
"vector_db_provider": "redis",
|
|
144
|
+
"vector_db_url": "redis://user:password@localhost:6379"
|
|
145
|
+
})
|
|
128
146
|
|
|
129
|
-
#
|
|
130
|
-
|
|
147
|
+
# Redis with SSL
|
|
148
|
+
config.set_vector_db_config({
|
|
149
|
+
"vector_db_provider": "redis",
|
|
150
|
+
"vector_db_url": "rediss://localhost:6380"
|
|
151
|
+
})
|
|
131
152
|
```
|
|
132
153
|
|
|
133
|
-
##
|
|
154
|
+
## Requirements
|
|
134
155
|
|
|
135
|
-
|
|
156
|
+
- Python >= 3.11, <= 3.13
|
|
157
|
+
- redisvl >= 0.6.0, <= 1.0.0
|
|
158
|
+
- cognee >= 0.2.0.dev0
|
|
136
159
|
|
|
137
|
-
|
|
138
|
-
- `embedding_engine`: The `EmbeddingEngine` to use for text vectorization (required)
|
|
139
|
-
- `api_key`: Optional API key parameter (not used for Redis but part of the interface)
|
|
160
|
+
## Advanced Usage
|
|
140
161
|
|
|
141
|
-
|
|
162
|
+
For direct adapter usage (advanced users only):
|
|
142
163
|
|
|
143
164
|
```python
|
|
144
|
-
|
|
145
|
-
|
|
165
|
+
from cognee.infrastructure.databases.vector.embeddings.EmbeddingEngine import EmbeddingEngine
|
|
166
|
+
from cognee_community_vector_adapter_redis import RedisAdapter
|
|
167
|
+
from cognee.infrastructure.engine import DataPoint
|
|
146
168
|
|
|
147
|
-
#
|
|
148
|
-
|
|
169
|
+
# Initialize embedding engine and adapter
|
|
170
|
+
embedding_engine = EmbeddingEngine(model="your-model")
|
|
171
|
+
redis_adapter = RedisAdapter(
|
|
172
|
+
url="redis://localhost:6379",
|
|
173
|
+
embedding_engine=embedding_engine
|
|
174
|
+
)
|
|
149
175
|
|
|
150
|
-
#
|
|
151
|
-
redis_adapter
|
|
176
|
+
# Direct adapter operations
|
|
177
|
+
await redis_adapter.create_collection("my_collection")
|
|
178
|
+
data_points = [DataPoint(id="1", text="Hello", metadata={"index_fields": ["text"]})]
|
|
179
|
+
await redis_adapter.create_data_points("my_collection", data_points)
|
|
180
|
+
results = await redis_adapter.search("my_collection", query_text="Hello", limit=10)
|
|
152
181
|
```
|
|
153
182
|
|
|
154
|
-
|
|
155
183
|
## Error Handling
|
|
156
184
|
|
|
157
185
|
The adapter includes comprehensive error handling:
|