A FastAPI-based AI application for searching and chatting with Buddhist texts using RAG (Retrieval-Augmented Generation) technology.
Webuddhist AI provides an intelligent search and chat interface for Buddhist texts, supporting multiple search types including hybrid, semantic, BM25, and exact matching. The API uses LangGraph for agentic workflows and integrates with Milvus vector database for efficient text retrieval.
Returns the HTML chat interface.
Response: HTML content (text/html)
Health check endpoint that verifies environment variables and service status.
Response:
{
"status": "healthy"
}Error Response (500):
{
"detail": "Missing environment variables for Milvus or Gemini."
}Streaming chat endpoint using Server-Sent Events (SSE). This endpoint processes chat messages through a LangGraph workflow and streams responses in real-time.
Request Body:
{
"messages": [
{
"role": "user",
"content": "What is the meaning of compassion?"
}
]
}Response: Server-Sent Events stream with the following event types:
search_results: Search results from hybrid search tooltoken: Streaming text tokens from the AI modeldone: Indicates completionerror: Error information if something goes wrong
Example Event:
data: {"type": "token", "data": "Compassion is..."}
data: {"type": "search_results", "data": [...], "queries": {...}}
data: {"type": "done", "data": {}}
All search endpoints are prefixed with /search.
Returns API information and available search types.
Response:
{
"message": "OpenPecha Search API",
"version": "1.0.0",
"endpoints": {
"search": "/search"
},
"search_types": {
"hybrid": "Combined BM25 + semantic search (default)",
"bm25": "Keyword-based search",
"semantic": "Meaning-based search",
"exact": "Exact phrase matching"
},
"docs": "/docs"
}Debug endpoint to test basic search functionality.
Response:
{
"status": "success",
"raw_results": "...",
"results_type": "...",
"results_length": 5,
"first_result": "..."
}Unified search endpoint supporting multiple search types with filtering and hierarchical search capabilities.
Request Body:
{
"query": "དེ་ལ་མི་དགར་ཅི་ཞིག་ཡོད། །",
"search_type": "hybrid",
"limit": 10,
"return_text": true,
"hierarchical": false,
"parent_limit": null,
"filter": {
"title": "Some Title",
"language": "bo"
}
}Request Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
query |
string | Yes | - | The search query text (min length: 1) |
search_type |
string | No | "hybrid" | Type of search:hybrid, bm25, semantic, or exact |
limit |
integer | No | 10 | Maximum number of results (1-100) |
return_text |
boolean | No | true | If true, return full text in results |
hierarchical |
boolean | No | false | If true, perform parent->children two-stage search |
parent_limit |
integer | No | null | Max parents to retrieve when hierarchical=true (1-200) |
filter |
object | No | null | Optional filters (title, language) |
Filter Object:
{
"title": "Title Name" | ["Title1", "Title2"],
"language": "bo" | ["bo", "en"]
}Response:
{
"query": "དེ་ལ་མི་དགར་ཅི་ཞིག་ཡོད། །",
"search_type": "hybrid",
"results": [
{
"id": "449691587532670411",
"distance": 0.95,
"entity": {
"text": "དེ་ལ་མི་དགར་ཅི་ཞིག་ཡོད། །གང་ཕྱིར་འདི་དག་རང་བཞིན་མེད།"
}
}
],
"count": 1
}Search Types:
- hybrid (default): Combines BM25 keyword search with semantic vector search for best results
- bm25: Keyword-based search using BM25 algorithm
- semantic: Meaning-based search using vector embeddings
- exact: Exact phrase matching
Hierarchical Search:
When hierarchical: true, the search performs a two-stage process:
- First searches for parent documents matching the query
- Then searches for children of those parents
- Returns only the children results
This is useful for structured documents with parent-child relationships.
The following environment variables are required:
GEMINI_API_KEYorGOOGLE_API_KEY: Google Gemini API key for LLMMILVUS_URI: Milvus vector database URIMILVUS_TOKEN: Milvus authentication tokenMILVUS_COLLECTION_NAME: Name of the Milvus collection (default: "test_kangyur_tengyur")PORT: Server port (default: 8000)ENV: Environment mode (set to "development" for auto-reload)
# Install dependencies
pip install -r requirements.txt
# Run the server
python main.pyThe API will be available at http://localhost:8000 (or the port specified in PORT).
Interactive API documentation is available at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
- FastAPI: Web framework
- LangGraph: Agentic workflow orchestration
- LangChain: LLM integration
- Google Gemini: Language model
- Milvus: Vector database for semantic search
- Server-Sent Events (SSE): Real-time streaming
See LICENSE file for details.