Kenya Land Search & Property Legal AI Agent
# lands.ai
Kenya land and property legal assistant with grounded retrieval, citations, and admin ingestion tools.
## What the system does today
`lands.ai` is a modular-monolith application with:
- **Backend:** FastAPI (`backend/`) for query orchestration, RAG retrieval, ingestion, calculators, and audit logging.
- **Frontend:** Next.js + Tailwind (`frontend/`) for end-user Q&A and admin operations.
- **Data:** PostgreSQL + `pgvector` for sources/chunks/embeddings and audit events.
- **AI provider adapter:** configurable OpenAI-compatible LLM/embedding providers with deterministic fallback behavior for local development.
## Core capabilities
### Legal Q&A with citations
- Accepts Kenya land/property legal questions.
- Enforces a **domain guardrail** (off-topic questions are declined with guidance).
- Retrieves relevant local evidence from knowledge chunks.
- Applies evidence confidence checks and citation thresholds.
- Generates response with:
- answer text
- citations and retrieval metadata
- evidence confidence + final confidence
- legal disclaimer
- audit event ID and timestamp
### Fallback online research
When local evidence is weak and online fallback is enabled, the backend can:
1. Search online references (Wikipedia API by default)
2. Ingest relevant extracts as `web_reference`
3. Re-run retrieval on expanded local knowledge
Response payload includes:
- `online_research_used`
- `online_docs_ingested`
### Knowledge ingestion (admin)
- Ingests text documents.
- Ingests PDF uploads.
- Uses semantic chunking + topic extraction.
- Queues ingestion work via background tasks and returns immediate acknowledgment.
### Filtered retrieval
- Query supports filters by:
- `source_types`
- `topics`
- Frontend persists selected filters in URL params for shareable sessions.
### Legal calculators
- Stamp duty calculator (`urban`, `rural`, `agricultural` rates).
- Land rates estimator (county-based placeholder logic).
### Audit trail
- Persists each query/res …