-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvector_store.py
30 lines (22 loc) · 949 Bytes
/
vector_store.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from dotenv import load_dotenv
from langchain_core.documents import Document
from langchain_openai import OpenAIEmbeddings
from langchain_redis import RedisConfig, RedisVectorStore
load_dotenv()
REDIS_URL = os.environ.get("REDIS_URL", "redis://localhost:6379/0")
INDEX_NAME = os.environ.get("VECTOR_INDEX_NAME", "oregon_trail")
config = RedisConfig(index_name=INDEX_NAME, redis_url=REDIS_URL)
doc = Document(
page_content="the northern trail, of the blue mountains, was destroyed by a flood and is no longer safe to traverse. It is recommended to take the southern trail although it is longer."
)
def get_vector_store():
try:
config.from_existing = True
vector_store = RedisVectorStore(OpenAIEmbeddings(), config=config)
except:
print("Init vector store with document")
config.from_existing = False
# TODO: define vector store
vector_store = None
return vector_store