feat: migrate store to source_id

This commit is contained in:
Alex
2024-09-09 15:46:18 +01:00
parent 1bb81614a5
commit 2f9c72c1cf
10 changed files with 43 additions and 40 deletions

View File

@@ -5,6 +5,7 @@ def migrate_to_v1_vectorstore_mongo():
client = pymongo.MongoClient("mongodb://localhost:27017/")
db = client["docsgpt"]
vectors_collection = db["vectors"]
sources_collection = db["sources"]
for vector in vectors_collection.find():
if "location" in vector:
@@ -14,6 +15,12 @@ def migrate_to_v1_vectorstore_mongo():
vector["remote_data"] = None
vectors_collection.update_one({"_id": vector["_id"]}, {"$set": vector})
# move data from vectors_collection to sources_collection
for vector in vectors_collection.find():
sources_collection.insert_one(vector)
vectors_collection.drop()
client.close()
def migrate_faiss_to_v1_vectorstore():
@@ -36,13 +43,11 @@ def migrate_mongo_atlas_vector_to_v1_vectorstore():
db = client["docsgpt"]
vectors_collection = db["vectors"]
# mongodb atlas collection
documents_collection = db["documents"]
for vector in vectors_collection.find():
if "location" in vector:
del vector["location"]
if "retriever" not in vector:
vector["retriever"] = "classic"
vector["remote_data"] = None
vectors_collection.update_one({"_id": vector["_id"]}, {"$set": vector})
documents_collection.update_many({"store": vector["user"] + "/" + vector["name"]}, {"$set": {"source_id": str(vector["_id"])}})
client.close()