-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_databases.py
More file actions
executable file
·72 lines (60 loc) · 2.38 KB
/
Copy pathinit_databases.py
File metadata and controls
executable file
·72 lines (60 loc) · 2.38 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import chromadb
from chromadb.config import Settings
from pymongo import MongoClient, ASCENDING
from dotenv import load_dotenv
import os
from datetime import datetime
import logging
from pathlib import Path
def init_databases():
"""Initialize ChromaDB and MongoDB databases."""
try:
# Initialize MongoDB
mongo_client = MongoClient("mongodb://localhost:27017/")
db = mongo_client.resumeDB
# Drop existing unique index if it exists
try:
db.resumes.drop_index("personal_info.email_1")
except:
pass
# Create new compound index on both email and resume_id
db.resumes.create_index(
[
("personal_info.email", 1),
("_id", 1)
],
unique=True,
sparse=True # Allows multiple documents with missing email
)
# Create profile_roasts collection with indexes
try:
# Create unique index on profile_url
db.profile_roasts.create_index("profile_url", unique=True)
# Create index on last_updated for TTL (24 hours = 86400 seconds)
db.profile_roasts.create_index("last_updated", expireAfterSeconds=86400)
# Create index on platform for efficient queries
db.profile_roasts.create_index("platform")
print("✅ Profile roasts collection indexes created")
except Exception as e:
print(f"⚠️ Profile roasts indexes already exist or error: {e}")
# Other indexes
db.resumes.create_index([("created_at", -1)])
db.job_matches.create_index([("resume_id", 1), ("job_id", 1)])
# Initialize ChromaDB
# chroma_client = chromadb.PersistentClient(path="./data/chromadb")
collections = ["resume_embeddings", "job_embeddings"]
for name in collections:
try:
chroma_client.get_collection(name)
except:
chroma_client.create_collection(
name=name,
metadata={"hnsw:space": "cosine"}
)
return True
except Exception as e:
print(f"Database initialization error: {str(e)}")
return False
if __name__ == "__main__":
load_dotenv()
init_databases()