cj-dev-code/semantic_search
0
1import json2from azure.search.documents import SearchClient3from azure.core.credentials import AzureKeyCredential4 5from dotenv import load_dotenv6import os7 8if __name__ == "__main__":9 load_dotenv()10 11 # ๐ Replace with your actual info12 endpoint = os.getenv('AZURE_AAIS_ENDPT')13 key = os.getenv('AZURE_AAIS_KEY')14 index_name = "main"15 16 client = SearchClient(17 endpoint=endpoint,18 index_name=index_name,19 credential=AzureKeyCredential(key)20 )21 22 # ๐ Load your documents23 docs = []24 with open("data/chunks_indexed.jsonl", "r", encoding="utf-8") as f:25 for line in f:26 doc = json.loads(line)27 doc["id"] = str(doc["id"]) # force id to string bc error idw pay more for28 docs.append(doc)29 30 # ๐ Upload in batches (Azure supports up to 1000 per batch)31 batch_size = 100032 for i in range(0, len(docs), batch_size):33 batch = docs[i:i + batch_size]34 result = client.upload_documents(documents=batch)35 print(f"Batch {i // batch_size + 1}:")36 