File size: 7,741 Bytes
3029aa1
 
 
 
 
 
 
7817fe3
3029aa1
 
7817fe3
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7817fe3
3029aa1
 
 
 
 
 
7817fe3
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7817fe3
3029aa1
 
 
 
 
 
 
 
d9c155c
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9c155c
3029aa1
 
7817fe3
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9c155c
7817fe3
3029aa1
 
 
 
 
 
d9c155c
3029aa1
 
 
 
 
 
 
 
 
 
 
d9c155c
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9c155c
3029aa1
 
 
 
 
7817fe3
3029aa1
 
d9c155c
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9c155c
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9c155c
3029aa1
 
 
 
 
 
 
 
 
 
7817fe3
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9c155c
3029aa1
7817fe3
3029aa1
d9c155c
3029aa1
 
 
 
 
 
 
 
d9c155c
3029aa1
 
 
 
 
 
 
 
 
 
7817fe3
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7817fe3
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9c155c
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7817fe3
3029aa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# Biblos Semantic Search API Documentation

Complete documentation for integrating the Biblos Semantic Search API into your applications.

## Base URL

```
https://dssjon-biblos-api.hf.space
```

The API is live and publicly accessible at the URL above.

---

## Endpoints

### 1. Health Check

**GET /**

Returns API status and basic information.

**Response:**
```json
{
  "status": "online",
  "model": "BAAI/bge-large-en-v1.5",
  "books_loaded": 66,
  "total_embeddings": 6407,
  "device": "cpu"
}
```

**Example:**
```bash
curl https://dssjon-biblos-api.hf.space/
```

---

### 2. Detailed Health Check

**GET /health**

Returns detailed health status and list of available books.

**Response:**
```json
{
  "model_loaded": true,
  "tokenizer_loaded": true,
  "embeddings_loaded": true,
  "books_available": ["gen", "exo", "lev", ...]
}
```

**Example:**
```bash
curl https://dssjon-biblos-api.hf.space/health
```

---

### 3. Semantic Search

**POST /search**

Perform semantic search over the entire Bible (both Old and New Testament).

#### Request Body

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `query` | string | Yes | Search query text (1-500 chars) |
| `limit` | integer | No | Number of results (1-100, default: 10) |

#### Response

```json
{
  "query": "string",
  "results": [
    {
      "book": "string",
      "chapter": integer,
      "testament": "string",
      "content": "string",
      "similarity": float
    }
  ],
  "total_searched": integer,
  "execution_time_ms": float
}
```

#### Example

```bash
curl -X POST https://dssjon-biblos-api.hf.space/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "faith without works is dead",
    "limit": 5
  }'
```

---

## Integration Examples

### JavaScript/TypeScript

#### Basic Fetch
```javascript
async function searchBible(query, limit = 10) {
  const response = await fetch('https://dssjon-biblos-api.hf.space/search', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      query,
      limit
    })
  })

  if (!response.ok) {
    throw new Error(`Search failed: ${response.status}`)
  }

  return await response.json()
}

// Usage
const results = await searchBible('love one another', 5)

console.log(results)
```

#### React Hook
```typescript
import { useState, useCallback } from 'react'

interface SearchResult {
  book: string
  chapter: number
  testament: string
  content: string
  similarity: number
}

export function useBibleSearch() {
  const [loading, setLoading] = useState(false)
  const [error, setError] = useState<Error | null>(null)

  const search = useCallback(async (
    query: string,
    limit: number = 10
  ): Promise<SearchResult[]> => {
    setLoading(true)
    setError(null)

    try {
      const response = await fetch('https://dssjon-biblos-api.hf.space/search', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ query, limit })
      })

      if (!response.ok) {
        throw new Error(`Search failed: ${response.status}`)
      }

      const data = await response.json()
      return data.results
    } catch (err) {
      const error = err instanceof Error ? err : new Error('Unknown error')
      setError(error)
      throw error
    } finally {
      setLoading(false)
    }
  }, [])

  return { search, loading, error }
}

// Usage in component
function SearchComponent() {
  const { search, loading, error } = useBibleSearch()
  const [results, setResults] = useState([])

  const handleSearch = async (query: string) => {
    const results = await search(query, 10)
    setResults(results)
  }

  return (
    // Your component JSX
  )
}
```

---

### Python

#### Basic Example
```python
import requests

def search_bible(query, limit=10):
    """
    Search the Bible using semantic search

    Args:
        query: Search query text
        limit: Number of results to return

    Returns:
        List of search results
    """
    url = 'https://dssjon-biblos-api.hf.space/search'

    payload = {
        'query': query,
        'limit': limit
    }

    response = requests.post(url, json=payload)
    response.raise_for_status()

    return response.json()

# Usage
results = search_bible(
    query='faith and works',
    limit=5
)

for result in results['results']:
    print(f"{result['book'].upper()} {result['chapter']}")
    print(f"Similarity: {result['similarity']:.3f}")
    print(f"Content: {result['content']}")
    print()
```

#### Async Example
```python
import asyncio
import aiohttp

async def search_bible_async(query, limit=10):
    """Async version of Bible search"""
    url = 'https://dssjon-biblos-api.hf.space/search'

    payload = {'query': query, 'limit': limit}

    async with aiohttp.ClientSession() as session:
        async with session.post(url, json=payload) as response:
            response.raise_for_status()
            return await response.json()

# Usage
async def main():
    results = await search_bible_async('love your neighbor', limit=5)
    print(results)

asyncio.run(main())
```

---

### cURL

```bash
curl -X POST https://dssjon-biblos-api.hf.space/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "blessed are the peacemakers",
    "limit": 3
  }' | jq '.results[] | "\(.book) \(.chapter) - \(.content)"'
```

---

## Error Handling

### HTTP Status Codes

| Code | Description |
|------|-------------|
| 200 | Success |
| 400 | Bad Request (invalid parameters) |
| 405 | Method Not Allowed |
| 500 | Internal Server Error |
| 503 | Service Unavailable (model not loaded) |

### Error Response Format

```json
{
  "detail": "Error message describing what went wrong"
}
```

### Example Error Handling (JavaScript)

```javascript
async function safeSearch(query) {
  try {
    const response = await fetch('https://dssjon-biblos-api.hf.space/search', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ query })
    })

    if (!response.ok) {
      const error = await response.json()
      throw new Error(error.detail || 'Search failed')
    }

    return await response.json()
  } catch (error) {
    console.error('Search error:', error.message)
    return null
  }
}
```

---

## Performance Considerations

### Response Times
- **First request**: 2-3 seconds (model loading)
- **Subsequent requests**: 50-100ms average
- **Cold start**: None (model stays in memory)

### Best Practices
1. **Cache results** on the client side when possible
2. **Debounce** search queries to reduce API calls
3. **Implement pagination** for large result sets
4. **Use appropriate limits** - higher limits increase response time
5. **The API searches the entire Bible** (both Old and New Testament) for comprehensive results

### Rate Limiting
Currently no rate limiting is enforced, but please use responsibly:
- Avoid making more than 10 requests per second
- Implement exponential backoff on errors
- Cache results when appropriate

---

## Interactive Documentation

Visit your Space URL at `/docs` for interactive Swagger UI documentation where you can:
- Test all endpoints directly in the browser
- See detailed schema information
- Try different parameter combinations
- View real-time responses

**Live Interactive Docs:** [https://dssjon-biblos-api.hf.space/docs](https://dssjon-biblos-api.hf.space/docs)

---

## Support

For issues, questions, or feature requests:
1. Check the interactive docs at `/docs`
2. Review this documentation
3. Open an issue on the GitHub repository
4. Contact the maintainer

---

## Version

API Version: 1.0.0
Model: BAAI/bge-large-en-v1.5
Last Updated: 2025