File size: 2,925 Bytes
f392000
 
 
 
 
 
 
 
 
 
 
7786671
 
f392000
7786671
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f392000
7786671
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Insight - Bahá'í Writings Search
emoji: 📚
colorFrom: green
colorTo: green
sdk: gradio
sdk_version: "5.49.1"
app_file: app.py
pinned: false
---

# Bahá'í Writings Semantic Search

A Gradio application that performs semantic search over Bahá'í Writings using OpenAI's text-embedding-3-large model and Pinecone for vector storage.

## Features

- **Semantic Search**: Find passages based on meaning and context, not just keywords
- **Document Processing**: Automatically processes .docx files and chunks by paragraphs  
- **Web Interface**: Clean, intuitive Streamlit interface
- **Relevance Ranking**: Results ranked by semantic similarity
- **Cloud Vector Storage**: Uses Pinecone for scalable, managed vector search

## Setup

### 1. Install Dependencies

```bash
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install dependencies
uv sync
```

### 2. Configure API Keys

Add your API keys to `.env`:

```
OPENAI_API_KEY = "your_openai_api_key_here"
PINECONE_API_KEY = "your_pinecone_api_key_here"
```

### 3. Ingest Documents

Process the Bahá'í writings documents:

```bash
uv run ingest.py
```

This will:
- Find all .docx files in the current directory
- Extract and chunk text by paragraphs
- Generate embeddings using OpenAI
- Store everything in Pinecone

### 4. Run the Application

```bash
uv run app.py
```

The application will be available at the URL printed out.

## Usage

1. Open the web interface
2. Enter your search query (concepts, themes, or specific topics)
3. Browse the semantically similar results
4. Click on results to read the full text

## Project Structure

```
├── pyproject.toml          # uv configuration and dependencies
├── .streamlit/
│   └── secrets.toml       # API keys configuration
├── ingest.py              # Document processing and ingestion script
├── app.py                 # Streamlit web application
└── gleanings-writings-bahaullah.docx  # Source document
```

## Dependencies

- **gradio**: Web interface framework
- **openai**: API client for embeddings
- **pinecone**: Cloud vector database for similarity search
- **python-docx**: Document processing
- **python-dotenv**: Environment variable management

## How It Works

1. **Ingestion**: Documents are processed paragraph by paragraph
2. **Embedding**: Each paragraph is converted to a vector using OpenAI's embedding model
3. **Storage**: Vectors and metadata are stored in Pinecone
4. **Search**: User queries are embedded and matched against stored vectors
5. **Ranking**: Results are ranked by cosine similarity

## Notes

- The application uses OpenAI's `text-embedding-3-large` model for high-quality embeddings
- Pinecone provides scalable, managed vector similarity search
- Semantic search finds conceptually related content beyond keyword matching
- Pinecone automatically handles index creation and management