xke commited on
Commit
1f64d9b
·
1 Parent(s): ce768bb

add back README

Browse files
Files changed (1) hide show
  1. README.md +63 -0
README.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: 'Chroma Q&A with Sources Element'
3
+ tags: ['chroma', 'chainlit', 'qa']
4
+ ---
5
+
6
+ # Chroma Q&A with Sources Element
7
+
8
+ This repository contains a Chainlit application that provides a question-answering service using documents stored in a Chroma vector store. It allows users to upload PDF documents, which are then chunked, embedded, and indexed for efficient retrieval. When a user asks a question, the application retrieves relevant document chunks and uses OpenAI's language model to generate an answer, citing the sources it used.
9
+
10
+ ## High-Level Description
11
+
12
+ The `app.py` script performs the following functions:
13
+
14
+ 1. **PDF Processing (`process_pdfs`)**: Chunks PDF files into smaller text segments, creates embeddings for each chunk, and stores them in Chroma.
15
+ 2. **Document Indexing (`index`)**: Uses `SQLRecordManager` to track document writes into the vector store.
16
+ 3. **Question Answering (`on_message`)**: When a user asks a question, the application retrieves relevant document chunks and generates an answer using OpenAI's language model, providing the sources for transparency.
17
+
18
+ ## Quickstart
19
+
20
+ ### Prerequisites
21
+
22
+ - Python 3.11 or higher
23
+ - Chainlit installed
24
+ - PDF documents to be indexed
25
+
26
+ ### Setup and Run
27
+
28
+ 1. **Install Dependencies:**
29
+
30
+ Install the required Python packages specified in `requirements.txt`.
31
+
32
+ ```shell
33
+ pip install -r requirements.txt
34
+ ```
35
+
36
+ 2. **Process PDFs:**
37
+
38
+ Place your PDF documents in the `./pdfs` directory.
39
+
40
+ 3. **Run the Application:**
41
+
42
+ Use the provided `Dockerfile` to build and run the application.
43
+
44
+ ```shell
45
+ docker build -t chroma-qa-chat .
46
+ docker run -p 7860:7860 chroma-qa-chat
47
+ ```
48
+
49
+ Access the application at `http://localhost:7860`.
50
+
51
+ ## Code Definitions
52
+
53
+ - `process_pdfs`: Function that processes PDF files and indexes them into Chroma.
54
+ - `on_chat_start`: Event handler that sets up the Chainlit session with the necessary components for question answering.
55
+ - `on_message`: Event handler that processes user messages, retrieves relevant information, and sends back an answer.
56
+ - `PostMessageHandler`: Callback handler that posts the sources of the retrieved documents as a Chainlit element.
57
+
58
+ ![Screenshot](./screenshot.png)
59
+
60
+ ## See Also
61
+
62
+ For a visual guide on how to use this application, watch the video by [Chris Alexiuk](https://www.youtube.com/watch?v=9SBUStfCtmk&ab_channel=ChrisAlexiuk).
63
+