File size: 4,514 Bytes
b773b72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
---
title: Church Fathers Commentary Search API
emoji: ✝️
colorFrom: purple
colorTo: blue
sdk: docker
pinned: false
license: mit
---

# Church Fathers Commentary Search API

Semantic search over Church Fathers' New Testament commentaries using BGE-large embeddings. This API keeps the model and embeddings in memory for fast responses (~50-100ms after initial load).

## Features

- ✅ Fast semantic search with BGE-large-en-v1.5 embeddings
- ✅ Model stays loaded in memory (no cold starts)
- ✅ Searches commentaries from 9 prominent Church Fathers
- ✅ Filter by book or father
- ✅ CORS enabled for easy integration
- ✅ RESTful JSON API with FastAPI
- ✅ Automatic API documentation at `/docs`

## API Endpoints

### `GET /`
Health check and API information

### `GET /health`
Detailed health status, available books, and fathers

### `POST /search`
Perform semantic search over commentaries

**Request Body:**
```json
{
  "query": "What did the fathers say about baptism?",
  "limit": 10,
  "books": ["matthew", "john"],  // Optional: filter by books
  "fathers": ["Augustine of Hippo"]  // Optional: filter by fathers
}
```

**Response:**
```json
{
  "query": "What did the fathers say about baptism?",
  "results": [
    {
      "book": "matthew",
      "father_name": "Augustine of Hippo",
      "source_title": "Tractates on the Gospel of John",
      "content": "Commentary text here...",
      "similarity": 0.892,
      "location_start": "Mt 3:13",
      "location_end": "Mt 3:17"
    }
  ],
  "total_searched": 4523,
  "execution_time_ms": 87.3
}
```

## Available Church Fathers

- Augustine of Hippo
- Athanasius of Alexandria
- Basil of Caesarea
- Gregory of Nazianzus
- Gregory of Nyssa
- Cyril of Alexandria
- Irenaeus
- Cyprian
- Origen of Alexandria

## Available Books

All 27 New Testament books: matthew, mark, luke, john, acts, romans, 1corinthians, 2corinthians, galatians, ephesians, philippians, colossians, 1thessalonians, 2thessalonians, 1timothy, 2timothy, titus, philemon, hebrews, james, 1peter, 2peter, 1john, 2john, 3john, jude, revelation

## Quick Start

### Using cURL
```bash
curl -X POST https://dssjon-biblos-cf-api.hf.space/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "grace and faith",
    "limit": 5
  }'
```

### Using JavaScript
```javascript
const response = await fetch('https://dssjon-biblos-cf-api.hf.space/search', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    query: 'grace and faith',
    limit: 5,
    books: ['romans', 'ephesians']
  })
})

const data = await response.json()
console.log(data.results)
```

### Using Python
```python
import requests

response = requests.post(
    'https://dssjon-biblos-cf-api.hf.space/search',
    json={
        'query': 'grace and faith',
        'limit': 5,
        'fathers': ['Augustine of Hippo']
    }
)

data = response.json()
print(data['results'])
```

## Interactive Documentation

Visit `/docs` on your deployed Space for interactive Swagger UI documentation where you can test the API directly.

## Performance

- First request: ~2-3 seconds (model loading)
- Subsequent requests: **50-100ms** (model already in memory)
- No cold starts after initial load
- Supports concurrent requests

## Model Information

- **Model:** BAAI/bge-large-en-v1.5
- **Embedding dimensions:** 1024
- **Commentary sources:** Historical Christian Faith Commentaries Database

## Data Source

The commentaries are sourced from the [Historical Christian Faith Commentaries Database](https://github.com/HistoricalChristianFaith/Commentaries-Database), an open-source collection of manually curated commentary texts from early Church Fathers.

## Deployment

This Space uses Docker SDK with FastAPI. The model and embeddings are loaded once at startup and kept in memory for fast responses.

## Local Development

1. Prepare data:
```bash
python prepare_data.py --source ../church-fathers/commentary_embeddings
```

2. Install dependencies:
```bash
pip install -r requirements.txt
```

3. Run locally:
```bash
uvicorn app:app --reload
```

4. Visit http://localhost:8000/docs for interactive API documentation

## License

MIT License - Free to use for any purpose

## Acknowledgments

- [Historical Christian Faith Commentaries Database](https://github.com/HistoricalChristianFaith/Commentaries-Database) for the original commentary data
- Hugging Face and the BGE team for the embedding model
- Anthropic Claude for assisting with development