Spaces:
Runtime error
Runtime error
Download src/components/vector_store.py from RDeepak/RAG-Embedding-Search-EPs: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/spaces/RDeepak/RAG-Embedding-Search-EPs/resolve/main/src/components/vector_store.py
- Command line
-
hf download hf://spaces/RDeepak/RAG-Embedding-Search-EPs/src/components/vector_store.py
-
curl -L -o vector_store.py https://huggingface.co/spaces/RDeepak/RAG-Embedding-Search-EPs/resolve/main/src/components/vector_store.py
1.53 kB
| import os | |
| import pandas as pd | |
| from tqdm import tqdm | |
| from src.utils.vector_store_utils import * | |
| from src.entity import VectorStoreConfig | |
| class VectorStore: | |
| def __init__(self, config:VectorStoreConfig): | |
| self.config = config | |
| self.pc_index=pc_client.Index(self.config.pc_index) | |
| def initiate_vector_upsertion(self, data_ingestion_dir): | |
| files = os.listdir(data_ingestion_dir) | |
| for file in files: | |
| namespace = file.split(".csv")[0] | |
| df = pd.read_csv(os.path.join(data_ingestion_dir, file)) | |
| df['description'] = df['title'] + ' \n ' + df['category'] | |
| records = df.to_dict('records') | |
| print(f"Category:{namespace} vector store...") | |
| BATCH_SIZE = 64 | |
| for i in tqdm(range(0, len(records), BATCH_SIZE)): | |
| try: | |
| batch = records[i:i+BATCH_SIZE] | |
| pc_records = [] | |
| for product in batch: | |
| product_ebd = get_embedding(product['description']) | |
| pc_record = { | |
| 'id': product['objectID'], | |
| 'values': product_ebd.flatten().tolist() | |
| } | |
| pc_records.append(pc_record) | |
| self.pc_index.upsert(vectors=pc_records, namespace=namespace) | |
| except Exception as e: | |
| raise CustomException(e, sys) |