File size: 1,210 Bytes
3254005
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
from fastapi import FastAPI, HTTPException
from rag_service import rag_service

app = FastAPI(
    title="Multi-Modal RAG API",
    description="API for querying documents with text and images",
    version="1.0.0"
)

@app.get("/")
async def root():
    return {"message": "Multi-Modal RAG API is running"}

@app.post("/ask")
async def ask_question(question: str):
    """
    Ask a question to the RAG system
    """
    try:
        response = rag_service.ask_question(question)
        return {
            "question": question,
            "response": response,
            "status": "success"
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error processing question: {str(e)}")

@app.get("/health")
async def health_check():
    """
    Health check endpoint
    """
    try:
        # Check if vectorstore is accessible
        count = rag_service.vectorstore._collection.count()
        return {
            "status": "healthy",
            "vectorstore_documents": count,
            "docstore_documents": len(rag_service.store.store)
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Health check failed: {str(e)}")