AI indexing completed

This commit is contained in:
timothyafolami
2024-08-16 17:37:28 +01:00
parent 713354371e
commit cff9511d86
13 changed files with 2843 additions and 257 deletions
+10 -12
View File
@@ -4,16 +4,12 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from utils import search, load_embedded_data
from utils import load_embedded_data, load_documents_from_directory, create_vector_store, save_embedded_data
from search import search_and_summarize
from data_ingest import load_data
app = FastAPI()
# Initialize global variables for FAISS index and vector store
try:
vector_store = load_embedded_data()
except Exception as e:
vector_store = None
# Define allowed origins for CORS
origins = [
@@ -37,19 +33,21 @@ class SearchRequest(BaseModel):
@app.get("/load_documents")
def load_documents(directory: str):
global vector_store
# Load documents using the utility function
vector_store = load_data(directory)
# loading the documents from the directory
documents, docs_id, num_pages = load_documents_from_directory(directory)
# embedding the documents
embed_db = create_vector_store(documents, docs_id, num_pages)
# saving the embedded data
status = save_embedded_data(embed_db)
return {"status": "Documents loaded successfully"}
@app.get("/search")
@app.post("/search")
def search(request: SearchRequest):
global vector_store
# Perform search using the utility function
results = search(vector_store, request.query)
results = search_and_summarize(request.query)
return {"results": results}