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