|
2 | 2 |
|
3 | 3 | import json
|
4 | 4 | import uuid
|
5 |
| -from typing import Any, Callable, Iterable, List, Optional, Tuple |
| 5 | +from typing import Any, Callable, Iterable, List, Mapping, Optional |
| 6 | + |
| 7 | +import numpy as np |
| 8 | +from redis.commands.search.query import Query |
6 | 9 |
|
7 | 10 | from langchain.docstore.document import Document
|
8 | 11 | from langchain.embeddings.base import Embeddings
|
9 |
| -from langchain.vectorstores.base import VectorStore |
10 | 12 | from langchain.utils import get_from_dict_or_env
|
11 |
| -from redis.commands.search.query import Query |
12 |
| -import numpy as np |
| 13 | +from langchain.vectorstores.base import VectorStore |
13 | 14 |
|
14 | 15 |
|
15 | 16 | class RediSearch(VectorStore):
|
@@ -80,7 +81,9 @@ def similarity_search(
|
80 | 81 | .paging(0, k)
|
81 | 82 | .dialect(2)
|
82 | 83 | )
|
83 |
| - params_dict = {"vector": np.array(embedding).astype(dtype=np.float32).tobytes()} |
| 84 | + params_dict: Mapping[str, str] = { |
| 85 | + "vector": str(np.array(embedding).astype(dtype=np.float32).tobytes()) |
| 86 | + } |
84 | 87 |
|
85 | 88 | # perform vector search
|
86 | 89 | results = self.client.ft(self.index_name).search(redis_query, params_dict)
|
@@ -115,15 +118,14 @@ def from_texts(
|
115 | 118 | redisearch = RediSearch.from_texts(
|
116 | 119 | texts,
|
117 | 120 | embeddings,
|
118 |
| - redis_url="redis://username:password@localhost:6379" |
| 121 | + redisearch_url="redis://username:password@localhost:6379" |
119 | 122 | )
|
120 | 123 | """
|
121 | 124 | redisearch_url = get_from_dict_or_env(
|
122 | 125 | kwargs, "redisearch_url", "REDISEARCH_URL"
|
123 | 126 | )
|
124 | 127 | try:
|
125 | 128 | import redis
|
126 |
| - from redis.commands.search.query import Query |
127 | 129 | from redis.commands.search.field import TextField, VectorField
|
128 | 130 | from redis.commands.search.indexDefinition import IndexDefinition, IndexType
|
129 | 131 | except ImportError:
|
@@ -165,7 +167,7 @@ def from_texts(
|
165 | 167 | try:
|
166 | 168 | client.ft(index_name).info()
|
167 | 169 | print("Index already exists")
|
168 |
| - except: |
| 170 | + except: # noqa |
169 | 171 | # Create RediSearch Index
|
170 | 172 | client.ft(index_name).create_index(
|
171 | 173 | fields=fields,
|
|
0 commit comments