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
7 changes: 6 additions & 1 deletion db_update/Update.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import os
import hashlib
from dotenv import dotenv_values
from pinecone import Pinecone, ServerlessSpec
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
Expand Down Expand Up @@ -100,9 +101,13 @@ def update_database(overwrite=(len(sys.argv) > 1 and sys.argv[1] == '--overwrite
values = [float(emb_array[i]) for i in indices]
sparse_vector = {"indices": indices, "values": values}

# Use a URL-based hash as the Pinecone vector ID.
# guaranteed unique per article since URLs are already deduplicated.
vector_id = hashlib.md5(url.encode()).hexdigest()

# Construct record exactly as per Pinecone documentation
record = {
"id": str(article.get("id", "")),
"id": vector_id,
"values": dense_vector,
"sparse_values": sparse_vector,
"metadata": {
Expand Down