Skip to content
Open
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
14 changes: 10 additions & 4 deletions utils/mongo_utils.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
from pymongo import MongoClient

from utils.config import DB_NAME, MONGO_URI, TENDERS_COLLECTION, VECTOR_COLLECTION
from bson.objectid import ObjectId
from utils.config import MONGO_URI, DB_NAME, VECTOR_COLLECTION, TENDERS_COLLECTION

mongo = MongoClient(MONGO_URI)
db = mongo[DB_NAME]

vector_collection = db[VECTOR_COLLECTION]
tenders_collection = db[TENDERS_COLLECTION]

ALLOWED_INDUSTRIES = ["Water & Sanitation", "Power & Energy"]

def store_embeddings_in_db(embeddings, document_name, tender_id):
try:
vector_collection.insert_many(embeddings)
except Exception as e:
print(f"❌ Mongo Insert Error: {e}")


def get_tender_ids(min_value):
cursor = tenders_collection.find({"tender_value": {"$gte": min_value}}, {"_id": 1})
cursor = tenders_collection.find(
{
"tender_value": {"$gte": min_value},
"industries": {"$in": ALLOWED_INDUSTRIES} # filter by industries
},
{"_id": 1}
)
return [str(doc["_id"]) for doc in cursor]