aucourt-ingest/aucourt_ingest/api/app.py
slothitude 6374aea0a2 Stage 9: add read-only FastAPI query API for juror RAG queries
8 GET endpoints under /api/v1 for health, personas, cases, vector search,
juror context, and hybrid search. Includes QueryService composing SubgraphQuery
+ VectorIndex + GraphDB, Pydantic response models, error handlers, and
`serve` CLI mode via uvicorn. 20 new tests, 190 total, zero regressions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-30 12:08:55 +10:00

41 lines
1.2 KiB
Python

"""FastAPI app factory for the query API."""
from __future__ import annotations
from contextlib import asynccontextmanager
from fastapi import FastAPI
from aucourt_ingest.api import dependencies
from aucourt_ingest.api.errors import register_error_handlers
from aucourt_ingest.api.routes import router
from aucourt_ingest.api.service import QueryService
from aucourt_ingest.storage.graph_db import GraphDB
def create_app(graph_db: GraphDB, vector_index, max_tokens: int = 4000) -> FastAPI:
"""Create and configure the FastAPI app.
Args:
graph_db: GraphDB instance (InMemoryGraphDB or Neo4jGraphDB)
vector_index: VectorIndex instance (or duck-typed fake for tests)
max_tokens: Default token budget for juror context assembly
"""
dependencies._query_service = QueryService(graph_db, vector_index, max_tokens)
@asynccontextmanager
async def lifespan(app: FastAPI):
yield
await graph_db.close()
app = FastAPI(
title="AuCourtIngest Query API",
description="Read-only juror RAG query API for Australian legal cases",
version="0.1.0",
lifespan=lifespan,
)
app.include_router(router)
register_error_handlers(app)
return app