47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from quart import Blueprint, jsonify
|
|
from quart_jwt_extended import jwt_refresh_token_required
|
|
|
|
from .logic import get_vector_store_stats, index_documents, vector_store
|
|
|
|
rag_blueprint = Blueprint("rag_api", __name__, url_prefix="/api/rag")
|
|
|
|
|
|
@rag_blueprint.get("/stats")
|
|
@jwt_refresh_token_required
|
|
async def get_stats():
|
|
"""Get vector store statistics."""
|
|
stats = get_vector_store_stats()
|
|
return jsonify(stats)
|
|
|
|
|
|
@rag_blueprint.post("/index")
|
|
@jwt_refresh_token_required
|
|
async def trigger_index():
|
|
"""Trigger indexing of documents from Paperless-NGX."""
|
|
try:
|
|
await index_documents()
|
|
stats = get_vector_store_stats()
|
|
return jsonify({"status": "success", "stats": stats})
|
|
except Exception as e:
|
|
return jsonify({"status": "error", "message": str(e)}), 500
|
|
|
|
|
|
@rag_blueprint.post("/reindex")
|
|
@jwt_refresh_token_required
|
|
async def trigger_reindex():
|
|
"""Clear and reindex all documents."""
|
|
try:
|
|
# Clear existing documents
|
|
collection = vector_store._collection
|
|
all_docs = collection.get()
|
|
|
|
if all_docs["ids"]:
|
|
collection.delete(ids=all_docs["ids"])
|
|
|
|
# Reindex
|
|
await index_documents()
|
|
stats = get_vector_store_stats()
|
|
return jsonify({"status": "success", "stats": stats})
|
|
except Exception as e:
|
|
return jsonify({"status": "error", "message": str(e)}), 500
|