File size: 2,318 Bytes
ea9ca44
 
 
 
 
 
 
 
ad01d65
 
ea9ca44
ad01d65
ea9ca44
ad01d65
ea9ca44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad01d65
 
ea9ca44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import sys
import os
import time

# Add 'backend' directory to path so we can import 'supabase_ingest' directly
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))

from src.embeddings.local_embedder import safe_generate_and_store_embeddings
from supabase_ingest import client

import uuid
# Mock data
user_id = str(uuid.uuid4())
extracted_data = {
    "headline": "Debug Engineer",
    "summary": "This is a test summary for debugging.",
    "skills": "Debug, Python",  # DB stores as string
    "technical_skills": "SQL, Vector DB", # DB stores as string
    "certifications": "",
    "languages": "English" # DB stores as string
}

print(f"DEBUG: Testing embedding storage for User ID: {user_id}")

# 1. Ensure user exists in profiles first (FK constraint)
try:
    print("DEBUG: Ensuring profile exists...")
    # UPSERT the mock data into the profiles table so the function can fetch it
    profile_payload = {
        "id": user_id,
        "full_name": "Debug User",
        "email": f"debug_{int(time.time())}@example.com",
        "phone": "+919876543210",
        "updated_at": "now()",
        # Add the fields we expect to be there
        "headline": extracted_data["headline"],
        "summary": extracted_data["summary"],
        "skills": extracted_data["skills"],
        "technical_skills": extracted_data["technical_skills"],
        "certifications": extracted_data["certifications"],
        "languages": extracted_data["languages"]
    }
    client.table("profiles").upsert(profile_payload).execute()
    print("DEBUG: Profile upserted.")
except Exception as e:
    print(f"❌ Failed to create test profile: {e}")
    sys.exit(1)

# 2. Run the function
print("DEBUG: Running safe_generate_and_store_embeddings...")
# Now it fetches from DB internally, so we don't pass extracted_data
safe_generate_and_store_embeddings(client, user_id)

# 3. Check if it exists
try:
    print("DEBUG: Verifying storage...")
    resp = client.table("profile_embeddings").select("*").eq("id", user_id).execute()
    if resp.data:
        print("✅ SUCCESS: Embedding record found!")
        print(f"Data keys: {resp.data[0].keys()}")
    else:
        print("❌ FAILURE: No record found in profile_embeddings.")
except Exception as e:
    print(f"❌ Verification failed: {e}")