vector indexes to be named after mongo _id

This commit is contained in:
ManishMadan2882
2024-08-11 19:33:31 +05:30
parent 3c6fd365fb
commit 1eb168be55
4 changed files with 34 additions and 51 deletions

View File

@@ -3,7 +3,7 @@ import datetime
from flask import Blueprint, request, send_from_directory
from pymongo import MongoClient
from werkzeug.utils import secure_filename
from bson.objectid import ObjectId
from application.core.settings import settings
mongo = MongoClient(settings.MONGO_URI)
@@ -35,7 +35,12 @@ def upload_index_files():
return {"status": "no name"}
job_name = secure_filename(request.form["name"])
tokens = secure_filename(request.form["tokens"])
save_dir = os.path.join(current_dir, "indexes", user, job_name)
""""
ObjectId serves as a dir name in application/indexes,
and for indexing the vector metadata in the collection
"""
_id = ObjectId()
save_dir = os.path.join(current_dir, "indexes", str(_id))
if settings.VECTOR_STORE == "faiss":
if "file_faiss" not in request.files:
print("No file part")
@@ -58,6 +63,7 @@ def upload_index_files():
# create entry in vectors_collection
vectors_collection.insert_one(
{
"_id":_id,
"user": user,
"name": job_name,
"language": job_name,

View File

@@ -116,18 +116,17 @@ def delete_by_ids():
def delete_old():
"""Delete old indexes."""
import shutil
path = request.args.get("path")
dirs = path.split("/")
dirs_clean = []
for i in range(0, len(dirs)):
dirs_clean.append(secure_filename(dirs[i]))
# check that path strats with indexes or vectors
if dirs_clean[0] not in ["indexes", "vectors"]:
return {"status": "error"}
path_clean = "/".join(dirs_clean)
vectors_collection.delete_one({"name": dirs_clean[-1], "user": dirs_clean[-2]})
name = request.args.get("name")
user = request.args.get("user")
doc = vectors_collection.find_one({
"user":user,
"name":name
})
print("user",user)
print("file",name)
if(doc is None):
return {"status":"not found"},404
path_clean = doc["location"]
if settings.VECTOR_STORE == "faiss":
try:
shutil.rmtree(os.path.join(current_dir, path_clean))