Spaces:
Sleeping
Sleeping
RAG PDF Assistant
Initial commit: Production-ready RAG PDF Assistant with HuggingFace integration
1b31f0c Download retrieval/vector_store.py from EbiAraz/RAG-PDF-Project: direct link, hf CLI and curl.
- Browser
- Download file 408 Bytes
-
https://huggingface.co/spaces/EbiAraz/RAG-PDF-Project/resolve/main/retrieval/vector_store.py
- Command line
-
hf download hf://spaces/EbiAraz/RAG-PDF-Project/retrieval/vector_store.py
-
curl -L -o vector_store.py https://huggingface.co/spaces/EbiAraz/RAG-PDF-Project/resolve/main/retrieval/vector_store.py
408 Bytes
| import faiss | |
| import numpy as np | |
| def create_index(vectors): | |
| # Handle empty vectors | |
| if vectors.size == 0 or len(vectors.shape) == 1: | |
| raise ValueError( | |
| 'No valid text found in PDF. ' | |
| 'Ensure the PDF contains extractable text content.' | |
| ) | |
| dimension = vectors.shape[1] | |
| index = faiss.IndexFlatL2(dimension) | |
| index.add(vectors) | |
| return index |