Loading documents: 0it [00:00, ?it/s] Splitting documents: 0it [00:00, ?it/s]…
- User
Loading documents: 0it [00:00, ?it/s] Splitting documents: 0it [00:00, ?it/s] INFO:sentence_transformers.SentenceTransformer:Load pretrained SentenceTransformer: thenlper/gte-large INFO:faiss.loader:Loading faiss with AVX2 support. INFO:faiss.loader:Could not load library with AVX2 support due to: ModuleNotFoundError("No module named 'faiss.swigfaiss_avx2'") INFO:faiss.loader:Loading faiss. INFO:faiss.loader:Successfully loaded faiss. Traceback (most recent call last): File "e:\LLMS\Fine-tuning\LlmsComponents\ragworld\ragsystem.py", line 260, in main() File "e:\LLMS\Fine-tuning\LlmsComponents\ragworld\ragsystem.py", line 236, in main vector_store = create_embeddings(split_docs) File "e:\LLMS\Fine-tuning\LlmsComponents\ragworld\ragsystem.py", line 193, in create_embeddings vector_store = FAISS.from_documents( File "C:\Users\hemanthk.LAP53-FJS.000\AppData\Local\Programs\Python\Python310\lib\site-packages\langchain_core\vectorstores.py", line 550, in from_documents return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs) File "C:\Users\hemanthk.LAP53-FJS.000\AppData\Local\Programs\Python\Python310\lib\site-packages\langchain_community\vectorstores\faiss.py", line 931, in from_texts return cls.__from( File "C:\Users\hemanthk.LAP53-FJS.000\AppData\Local\Programs\Python\Python310\lib\site-packages\langchain_community\vectorstores\faiss.py", line 888, in __from index = faiss.IndexFlatL2(len(embeddings[0])) IndexError: list index out of range import os import logging import shutil from typing import List, Optional, Dict from pathlib import Path from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor import json import yaml import pandas as pd import docx import pptx import fitz # PyMuPDF for PDF processing import nltk from nltk.tokenize import word_tokenize from nltk.corpus import stopwords from datasets import Dataset from transformers import AutoTokenizer from tqdm import tqdm from langchain.docstore.document import Document as LangchainDocument from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain_community.vectorstores import FAISS from langchain_huggingface import HuggingFaceEmbeddings from langchain_community.vectorstores.utils import DistanceStrategy
Set up logging
logging.basicConfig(level=logging.INFO) logger = logging.getLogger(name)
Download necessary NLTK resources quietly
nltk.download('punkt', quiet=True) nltk.download('stopwords', quiet=True)
Constants
EMBEDDING_MODEL_NAME = "thenlper/gte-large" # Replace with your preferred model CHUNK_SIZE = 500 # Adjust based on your needs CHUNK_OVERLAP = 50 # Overlap between chunks for context
def extract_text_from_pdf(file_path: Path) -> str: """Extract text from a PDF file.""" try: with fitz.open(file_path) as doc: text = "" for page in doc: text += page.get_text() return text except Exception as e: logger.error(f"Error reading PDF file {file_path}: {e}") return ""
def extract_text_from_docx(file_path: Path) -> str: """Extract text from a Word document.""" try: doc = docx.Document(file_path) text = "\n".join([para.text for para in doc.paragraphs]) return text except Exception as e: logger.error(f"Error reading DOCX file {file_path}: {e}") return ""
- Assistant