Created
July 21, 2024 16:31
-
-
Save idontcalculate/bb88a5c1de6212e360452243cebde703 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from config import COLLECTION_NAME | |
import os | |
import csv | |
from qdrant_client.http.models import VectorParams, PointStruct | |
from dotenv import load_dotenv | |
from generate_embedding import get_book_vector | |
from connect_qdrant import get_qdrant_client | |
load_dotenv() | |
qdrant_client = get_qdrant_client() | |
# Read and insert documents from CSV | |
csv_file_path = "/mnt/c/Users/SUPERADMIN/book-hunt-engine/data/books.csv" | |
with open(csv_file_path, newline='', encoding='utf-8') as csvfile: | |
reader = csv.DictReader(csvfile) | |
for row in reader: | |
doc_id = int(row["isbn13"]) | |
vector = get_book_vector(row) | |
payload = { | |
"title": row["title"], | |
"isbn10": row["isbn10"], | |
"isbn13": row["isbn13"], | |
"categories": row["categories"], | |
"thumbnail": row["thumbnail"], | |
"description": row["description"], | |
"num_pages": int(row["num_pages"]), | |
"average_rating": float(row["average_rating"]), | |
"published_year": int(row["published_year"]), | |
"authors": row["authors"].split(", ") | |
} | |
qdrant_client.upsert( | |
collection_name=COLLECTION_NAME, | |
points=[ | |
PointStruct( | |
id=doc_id, | |
vector=vector, | |
payload=payload | |
) | |
] | |
) | |
print("Documents added successfully.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment