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.
@@ -13,5 +13,12 @@ wheels/
13
13
  .env
14
14
 
15
15
  # Cognee system
16
+ # for backward compatibility
16
17
  .cognee-data
17
18
  .cognee-system
19
+
20
+ # for new version
21
+ .cognee_data
22
+ .cognee_system
23
+ .data_storage
24
+ *.log
@@ -1,10 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cognee-community-vector-adapter-redis
3
- Version: 0.0.1
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>=0.2.0.dev0
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
  [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
20
- ![Language](https://img.shields.io/badge/python-3.8+-blue.svg)
22
+ ![Language](https://img.shields.io/badge/python-3.11+-blue.svg)
21
23
 
22
24
  [![Powered by RedisVL](https://img.shields.io/badge/Powered%20by-RedisVL-red.svg)](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
- from cognee.infrastructure.databases.vector.embeddings.EmbeddingEngine import EmbeddingEngine
75
- from cognee_community_vector_adapter_redis import RedisAdapter
76
-
77
- # Initialize your embedding engine
78
- embedding_engine = EmbeddingEngine(
79
- model="your-model",
80
- # ... other config
81
- )
82
-
83
- # Create Redis adapter
84
- redis_adapter = RedisAdapter(
85
- url="redis://localhost:6379", # Redis connection URL
86
- embedding_engine=embedding_engine,
87
- api_key=None # Optional, not used for Redis but part of interface
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
- # Create a collection
91
- await redis_adapter.create_collection("my_collection")
126
+ ## Configuration
92
127
 
93
- # Add data points
94
- from cognee.infrastructure.engine import DataPoint
128
+ Configure Redis as your vector database in cognee:
95
129
 
96
- data_points = [
97
- DataPoint(id="1", text="Hello world", metadata={"index_fields": ["text"]}),
98
- DataPoint(id="2", text="Redis vector search", metadata={"index_fields": ["text"]})
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
- await redis_adapter.create_data_points("my_collection", data_points)
134
+ ### Environment Variables
102
135
 
103
- # Search for similar vectors
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
- # Search with pre-computed vector
111
- query_vector = await redis_adapter.embed_data(["Hello Redis"])
112
- results = await redis_adapter.search(
113
- collection_name="my_collection",
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
- # Batch search
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
- # Retrieve specific data points
127
- retrieved = await redis_adapter.retrieve(
128
- collection_name="my_collection",
129
- data_point_ids=["1", "2"]
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
- # Delete data points
133
- await redis_adapter.delete_data_points(
134
- collection_name="my_collection",
135
- data_point_ids=["1"]
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
- # Check if collection exists
139
- exists = await redis_adapter.has_collection("my_collection")
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
- ## Configuration
165
+ ## Requirements
143
166
 
144
- The Redis adapter supports the following configuration options:
167
+ - Python >= 3.11, <= 3.13
168
+ - redisvl >= 0.6.0, <= 1.0.0
169
+ - cognee >= 0.2.0.dev0
145
170
 
146
- - `url`: Redis connection URL (e.g., "redis://localhost:6379", "redis://user:pass@host:port")
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
- ### Connection URL Examples
173
+ For direct adapter usage (advanced users only):
151
174
 
152
175
  ```python
153
- # Local Redis
154
- redis_adapter = RedisAdapter(url="redis://localhost:6379", embedding_engine=engine)
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
- # Redis with authentication
157
- redis_adapter = RedisAdapter(url="redis://user:password@localhost:6379", embedding_engine=engine)
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
- # Redis with SSL
160
- redis_adapter = RedisAdapter(url="rediss://localhost:6380", embedding_engine=engine)
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
  [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
11
- ![Language](https://img.shields.io/badge/python-3.8+-blue.svg)
11
+ ![Language](https://img.shields.io/badge/python-3.11+-blue.svg)
12
12
 
13
13
  [![Powered by RedisVL](https://img.shields.io/badge/Powered%20by-RedisVL-red.svg)](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
- from cognee.infrastructure.databases.vector.embeddings.EmbeddingEngine import EmbeddingEngine
66
- from cognee_community_vector_adapter_redis import RedisAdapter
67
-
68
- # Initialize your embedding engine
69
- embedding_engine = EmbeddingEngine(
70
- model="your-model",
71
- # ... other config
72
- )
73
-
74
- # Create Redis adapter
75
- redis_adapter = RedisAdapter(
76
- url="redis://localhost:6379", # Redis connection URL
77
- embedding_engine=embedding_engine,
78
- api_key=None # Optional, not used for Redis but part of interface
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
- # Create a collection
82
- await redis_adapter.create_collection("my_collection")
115
+ ## Configuration
83
116
 
84
- # Add data points
85
- from cognee.infrastructure.engine import DataPoint
117
+ Configure Redis as your vector database in cognee:
86
118
 
87
- data_points = [
88
- DataPoint(id="1", text="Hello world", metadata={"index_fields": ["text"]}),
89
- DataPoint(id="2", text="Redis vector search", metadata={"index_fields": ["text"]})
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
- await redis_adapter.create_data_points("my_collection", data_points)
123
+ ### Environment Variables
93
124
 
94
- # Search for similar vectors
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
- # Search with pre-computed vector
102
- query_vector = await redis_adapter.embed_data(["Hello Redis"])
103
- results = await redis_adapter.search(
104
- collection_name="my_collection",
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
- # Batch search
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
- # Retrieve specific data points
118
- retrieved = await redis_adapter.retrieve(
119
- collection_name="my_collection",
120
- data_point_ids=["1", "2"]
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
- # Delete data points
124
- await redis_adapter.delete_data_points(
125
- collection_name="my_collection",
126
- data_point_ids=["1"]
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
- # Check if collection exists
130
- exists = await redis_adapter.has_collection("my_collection")
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
- ## Configuration
154
+ ## Requirements
134
155
 
135
- The Redis adapter supports the following configuration options:
156
+ - Python >= 3.11, <= 3.13
157
+ - redisvl >= 0.6.0, <= 1.0.0
158
+ - cognee >= 0.2.0.dev0
136
159
 
137
- - `url`: Redis connection URL (e.g., "redis://localhost:6379", "redis://user:pass@host:port")
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
- ### Connection URL Examples
162
+ For direct adapter usage (advanced users only):
142
163
 
143
164
  ```python
144
- # Local Redis
145
- redis_adapter = RedisAdapter(url="redis://localhost:6379", embedding_engine=engine)
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
- # Redis with authentication
148
- redis_adapter = RedisAdapter(url="redis://user:password@localhost:6379", embedding_engine=engine)
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
- # Redis with SSL
151
- redis_adapter = RedisAdapter(url="rediss://localhost:6380", embedding_engine=engine)
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:
@@ -1,3 +1,3 @@
1
1
  from .redis_adapter import RedisAdapter
2
2
 
3
- __all__ = ["RedisAdapter"]
3
+ __all__ = ["RedisAdapter"]