Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix allow_dangerous_deserialization bug #18

Merged
merged 8 commits into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions core/tools/dbops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,32 @@


def create_db_if_not_exists(db_name: str, embeddings: Embeddings):
if not exists('store/vector/' + db_name + '.faiss'):
print("Creating new database:", db_name + '.faiss')
tmp_db = FAISS.from_texts(['You are a large language model, intended for research purposes.'], embeddings)
tmp_db.save_local(folder_path='store/vector', index_name=db_name)
if not exists("store/vector/" + db_name + ".faiss"):
print("Creating new database:", db_name + ".faiss")
tmp_db = FAISS.from_texts(
["You are a large language model, intended for research purposes."],
embeddings,
)
tmp_db.save_local(folder_path="store/vector", index_name=db_name)
else:
print("Already exists:", db_name + '.faiss')
print("Already exists:", db_name + ".faiss")


def get_db_by_name(db_name: str, embeddings: Embeddings) -> FAISS:
create_db_if_not_exists(db_name, embeddings)
return FAISS.load_local(folder_path='store/vector', embeddings=embeddings, index_name=db_name, allow_dangerous_deserialization=True)

try:
# windows
db_connection = FAISS.load_local(
folder_path="store/vector",
embeddings=embeddings,
index_name=db_name,
allow_dangerous_deserialization=True,
)
except Exception:
# linux & mac
db_connection = FAISS.load_local(
folder_path="store/vector", embeddings=embeddings, index_name=db_name
)

return db_connection
Loading