Skip to content

Commit a02bd04

Browse files
berkecanrizaiManul from Pathway
authored andcommitted
slide search llm app #6896
GitOrigin-RevId: 2d1fc73f58e5d82136eef4b7753bab2cfc959dfe
1 parent 1f26e53 commit a02bd04

File tree

15 files changed

+1047
-0
lines changed

15 files changed

+1047
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
OPENAI_API_KEY=<YOUR OPENAI_API_KEY>
2+
3+
PATHWAY_HOST="0.0.0.0"
4+
5+
PATHWAY_NW_HOST=pathway_app
6+
7+
FILE_SERVER_URL=http://localhost:8080/
8+
9+
SEARCH_TOPK=6
10+
11+
SCHEMA_FILE_PATH="parse_schema.yaml"
12+
# to disable schema parsing, simply comment out the above line or set `SCHEMA_FILE_PATH=""`.
13+
14+
PATHWAY_LICENSE_KEY="YOUR PATHWAY KEY" # can be obtained here: https://pathway.com/user/license
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM pathwaycom/pathway:0.13.2
2+
3+
ENV DOCKER_BUILDKIT=1
4+
ENV PYTHONUNBUFFERED=1
5+
6+
RUN apt-get update && apt-get install -y \
7+
poppler-utils \
8+
libreoffice \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
WORKDIR /app
12+
13+
COPY . .
14+
15+
EXPOSE 8000
16+
17+
CMD ["python", "app.py"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM nginx:latest
2+
3+
COPY nginx.conf /etc/nginx/conf.d/default.conf
4+
5+
RUN mkdir -p /app/pw_dump_images /app/pw_dump_files
6+
7+
EXPOSE 8080 8443
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM pathwaycom/pathway:0.13.2
2+
3+
ENV PYTHONUNBUFFERED=1
4+
5+
WORKDIR /ui
6+
7+
COPY ui/requirements-ui.txt requirements-ui.txt
8+
9+
RUN pip install -U --no-cache-dir -r requirements-ui.txt
10+
11+
COPY ui/ .
12+
13+
EXPOSE 8501
14+
15+
CMD [ "streamlit", "run", "ui.py" ]
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# **Slide AI Search App**
2+
3+
## **Overview**
4+
5+
This app template will help you build a multi-modal search service using `GPT-4o` with Metadata Extraction and Vector Index. It uses [Pathway](https://github.com/pathwaycom/llm-app) for indexing and retrieving slides from PowerPoint and PDF presentations.
6+
7+
How is this different?
8+
9+
* Build highly accurate RAG pipelines powered by indexes that are updated in real-time.
10+
* Pathway uses vision language models to understand and index your presentations and PDFs, automatically updating as changes are made.
11+
* Get started with a minimalistic and production-ready approach.
12+
13+
Boost productivity with accurate search across your PowerPoints, PDFs, and Slides all within your work environment. Try out the [demo](https://sales-rag-chat.demo.pathway.com/#search-your-slide-decks) here.
14+
15+
16+
## Quickstart
17+
18+
Check the `.env.example`, create a new `.env` file and fill in the template.
19+
For a quick start, you need to only change the following fields:
20+
- `PATHWAY_LICENSE_KEY`
21+
- `OPENAI_API_KEY`
22+
23+
This app template is available for free via [Pathway Scale](https://pathway.com/features). Get your [license key here](https://pathway.com/user/license) and fill in the `PATHWAY_LICENSE_KEY` here in the `.env` file.
24+
25+
## How it Helps
26+
27+
**1) Improved Efficiency:**
28+
29+
* **Save Efforts:** You no longer need to manually sift through countless presentations.
30+
* **Faster Information Retrieval:** Instantly find specific information with a few keywords or descriptive prompts, saving you time when preparing for presentations or reviewing past projects.
31+
32+
**2) Enhanced Organization**
33+
34+
* **Automated Categorization:** You can organize your slide library by topic, project, or other criteria. Configure the schema file to cusomize the parsed fields.
35+
36+
**3) Enhanced Reliability**
37+
38+
* **Automatic Updates:** Hybrid indexes update automatically whenever a new slide is added or removed, ensuring your information is always current and accurate.
39+
40+
**4) Automated Slide Parsing:**
41+
42+
* Process PPTX and PDF slide decks with vision language models to extract the content.
43+
44+
**5) Flexible Data Sources:**
45+
46+
* Compatible with local directories, SharePoint, Google Drive, and other Pathway connectors, ensuring a wide range of application scenarios can be supported.
47+
48+
By automating the extraction and retrieval of slide information, this app addresses the critical pain point of managing and utilizing extensive slide decks efficiently, enhancing productivity and information accuracy for sales teams.
49+
50+
51+
## Architecture:
52+
53+
The architecture of the Slides AI Search App is designed to connect various local or cloud repositories, transforming and indexing slides for efficient querying. It supports integration with closed and open-source LLMs for enhanced search capabilities.
54+
55+
![Architecture](ai-slides-diagram.svg)
56+
57+
This demo consists of three parts:
58+
* `app.py`: Pathway app that handles parsing, indexing and backend.
59+
* `nginx`: File server that hosts images to be consumed by the UI.
60+
* `UI`: A Streamlit UI for interacting with the app.
61+
62+
63+
## How it works:
64+
65+
### **Data Ingestion**
66+
67+
1. **Data Sources**:
68+
* The application reads slide files (PPTX and PDF) from a specified directory. The directory is set to `./data/`in the `app.py` file.
69+
* In the default app setup, the connected folder is a local file folder. You can add more folders and file sources, such as [Google Drive](https://pathway.com/developers/user-guide/connectors/gdrive-connector/#google-drive-connector) or [Sharepoint](https://pathway.com/developers/user-guide/connecting-to-data/connectors/#tutorials), by adding a line of code to the template.
70+
* More inputs can be added by configuring the `sources` list in the `app.py`.
71+
72+
73+
### **Slide Parsing and Indexing**
74+
75+
76+
1. **Parsing**:
77+
* The [`SlideParser`](https://pathway.com/developers/api-docs/pathway-xpacks-llm/parsers#pathway.xpacks.llm.parsers.SlideParser) from Pathway is used to parse the slides. The parser is configured to parse a text description and schema that is defined in the `parse_schema.yaml`.
78+
* Our example schema includes fields such as `category`, `tags`, `title`, `main_color`, `language`, and `has_images`. This can be modified for specific use cases.
79+
* Note that, UI is configured to make use of two extracted fields `category` and `language`, these need to be kept for the UI to work. However, the app can still be used without the UI with different schemas or no parsed schema.
80+
2. **Embedding**:
81+
* Parsed slide content is embedded with the OpenAI's `text-embedding-ada-002` embedder.
82+
* The embeddings are then stored in Pathway's vector store using the `SlidesVectorStoreServer`.
83+
3. **Metadata Handling**:
84+
* Images and files are dumped into local directories (`storage/pw_dump_images` and `storage/pw_dump_files`).
85+
* Each slide gets a unique ID with `add_slide_id` function in the `app.py`. This helps with opening files and images from the the UI.
86+
87+
88+
### **Query Handling**
89+
90+
1. **Retrieval Augmented Generation (RAG)**:
91+
* The `DeckRetriever` class builds the backend, handling all steps of the application from parsing files to serving the endpoints. Refer to the [API docs](https://pathway.com/developers/api-docs/pathway-xpacks-llm/question_answering#pathway.xpacks.llm.question_answering.DeckRetriever) for more information.
92+
93+
## Pipeline Organization
94+
95+
This folder contains several components necessary for setting up and running the Sales Slide RAG application:
96+
97+
98+
1. **app.py**:
99+
* The main application that sets up the slide search functionality. It configures the OpenAI chat model, slide parser, vector store, and initializes the DeckRetriever for handling queries.
100+
2. **parse_schema.yaml**:
101+
* Defines the schema for parsing the slides and including fields such as `category`, `tags`, `title`, `main_color`, `language`, and `has_images`.
102+
* These fields will be appended to the `metadata`, if you prefer to also add them to `text` field, set `include_schema_in_text` of `SlideParser` to `True`.
103+
3. **.env**:
104+
* Config file for the environment variables, such as the OpenAI API key and Pathway key.
105+
106+
107+
## **Prerequisites/Configuration**
108+
109+
### **Environment Setup**
110+
111+
1. **OpenAI API Key**:
112+
* Get an API key from the [OpenAI’s API Key Management page](https://platform.openai.com/account/api-keys). Keep this API key secure.
113+
* Configure your key in the `.env` file.
114+
* You can refer to the stub file `.env.example` in this repository.
115+
* Note: This is only needed in OpenAI LLMs and embedders. It is also possible to use other multi-modal, local LLMs and embedders.
116+
117+
2. **Pathway’s License Key**:
118+
* This app template is available for free via [Pathway Scale](https://pathway.com/features).
119+
* Get your [license key here](https://pathway.com/user/license).
120+
121+
3. **SCHEMA_FILE_PATH**:
122+
* Path to file that defines the schema to be parsed. It can be kept as default and the `parse_schema.yaml` can be configured.
123+
124+
4. **SEARCH_TOPK**:
125+
* Number of elements to be retrieved from the index by default.
126+
127+
## How to run the project
128+
129+
Make sure you are in the right directory:
130+
```bash
131+
cd examples/pipelines/slides_search
132+
```
133+
134+
### Locally
135+
Running the whole demo without Docker is not suggested as there are three components.
136+
137+
1. **Download and Install LibreOffice:**
138+
* Download LibreOffice from the [LibreOffice website](https://www.libreoffice.org/download/download-libreoffice).
139+
* Follow the installation instructions specific to your operating system. \
140+
141+
2. **Verify LibreOffice Installation:**
142+
* Download LibreOffice from the LibreOffice website.
143+
* Open a terminal or command prompt and run the following command:
144+
* You should see the LibreOffice version information, indicating LibreOffice is installed correctly.
145+
146+
**Purpose:** LibreOffice helps with converting PPTX files into PDFs, which is essential for the document processing workflow in the Slides AI Search App.
147+
148+
If you are on Windows, please refer to the [running with Docker](#Running-with-docker) section below.
149+
150+
To run the Pathway app without the UI,
151+
152+
```bash
153+
python app.py
154+
```
155+
156+
### Running with Docker
157+
158+
Build the Docker with:
159+
160+
```bash
161+
docker-compose build
162+
```
163+
164+
And, run with:
165+
166+
```bash
167+
docker-compose up
168+
```
169+
170+
This will start all three components of the demo.
171+
172+
## Using the app
173+
174+
After Docker is running, you will see a stream of logs of your files being parsed.
175+
176+
### Accessing the UI
177+
178+
On your browser, visit [`http://localhost:8501`](http://localhost:8501/) to access the UI.
179+
180+
Here, you will see a search bar, some filters, and information about the indexed documents on the left side.
181+
182+
183+
### Sending requests to the server
184+
185+
#### With CURL
186+
187+
UI is not a necessary component, especially for developers. If you are interested in building your own app, check out the following ways to use the app:
188+
189+
First, let's check the indexed files:
190+
```bash
191+
curl -X 'POST' 'http://0.0.0.0:8000/v1/pw_list_documents' -H 'accept: */*' -H 'Content-Type: application/json'
192+
```
193+
194+
This will return a list of metadata from the indexed files.
195+
196+
Now, let's search through our slides:
197+
198+
199+
```bash
200+
curl -X 'POST' 'http://0.0.0.0:8000/v1/pw_ai_answer' -H 'accept: */*' -H 'Content-Type: application/json' -d '{
201+
"prompt": "diagrams that contain value propositions"
202+
}'
203+
```
204+
205+
This will search through our files, and return parsed slides with the `text`, `slide_id` and other `metadata` (also including the parsed schema).
206+
207+
#### With the Pathway RAG Client
208+
209+
Import RAGClient with:
210+
211+
```python
212+
from pathway.xpacks.llm.question_answering import RAGClient
213+
```
214+
215+
Initialize the client:
216+
217+
```python
218+
# conn = RAGClient(url=f"http://{PATHWAY_HOST}:{PATHWAY_PORT}")
219+
220+
# with the default config
221+
conn = RAGClient(url=f"http://localhost:8000")
222+
```
223+
224+
List the indexed files:
225+
```python
226+
conn.pw_list_documents()
227+
```
228+
> `[{'path': 'data/slide.pdf'}, ...`
229+
230+
Query the app:
231+
232+
```python
233+
conn.pw_ai_answer("introduction slide")
234+
```
235+
> `[{'dist': 0.47761982679367065, 'metadata': ...`
236+
237+
238+
## Not sure how to get started?
239+
240+
Let's discuss how we can help you build a powerful, customized RAG application. [Reach us here to talk or request a demo!](https://pathway.com/solutions/enterprise-generative-ai?modal=requestdemo)

examples/pipelines/slides_search/ai-slides-diagram.svg

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)