Spaces:
Sleeping
Sleeping
File size: 1,129 Bytes
836db00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import os
import faiss
import warnings
import nest_asyncio
from dotenv import load_dotenv
from llama_parse import LlamaParse
from llama_index.core import Settings
from llama_index.vector_stores.faiss import FaissVectorStore
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.core import VectorStoreIndex, StorageContext
load_dotenv()
nest_asyncio.apply()
warnings.filterwarnings("ignore")
def get_data(file_path):
parser = LlamaParse(
api_key=os.getenv('LLAMA_CLOUD_API_KEY'),
result_type="markdown"
)
docs = parser.load_data(file_path)
d = 384
faiss_index = faiss.IndexFlatL2(d)
embedding_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
Settings.embed_model = embedding_model
vector_store = FaissVectorStore(faiss_index=faiss_index)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
docs, storage_context=storage_context
)
index.storage_context.persist()
print("Data Parsed Successfully!!")
|