This Streamlit application enables users to upload PDF documents and perform question-answering using advanced retrieval and language model techniques.
- Function:
process_document()
- Purpose: Converts uploaded PDF files into text chunks
- Features:
- Uses PyMuPDFLoader for PDF parsing
- Applies RecursiveCharacterTextSplitter for text segmentation
- Handles temporary file management
- Chunk size: 400 characters
- Chunk overlap: 100 characters
- Database: ChromaDB
- Embedding Model: Snowflake Arctic Embed2
- Features:
- Persistent vector storage
- Cosine similarity search
- Metadata tracking for document chunks
- Retrieval Steps:
- Query vector collection
- Cross-encoder re-ranking
- Select top 3 most relevant document chunks
- Model: LLaMA 3.2
- Prompt Engineering:
- System prompt guides structured, context-based responses
- Ensures answer generation based solely on provided context
- Initializes ChromaDB collection
- Configures Ollama embedding function
- Sets up cosine similarity space
- Adds document chunks to vector store
- Generates unique IDs based on filename
- Stores document metadata
- Performs semantic search in vector collection
- Retrieves most relevant documents
- Uses MS MARCO MiniLM cross-encoder
- Re-ranks retrieved documents
- Selects top 3 most relevant chunks
- Streams responses from LLaMA 3.2
- Applies system prompt for structured answering
- Sidebar for PDF upload
- Main area for question input
- Streaming response display
- Expandable sections for retrieved documents
- Streamlit
- ChromaDB
- Ollama
- PyMuPDFLoader
- Sentence Transformers
- LangChain
- Install dependencies
- Ensure Ollama is running locally
- Download required embedding and language models
- Add error handling
- Implement multi-document support
- Create model configuration options
- Add citation/source tracking
- Temporary file management
- Handling file upload permissions
- Secure embedding and model usage
- Chunk size and overlap tuning
- Model selection
- Caching mechanisms
- Upload a PDF document
- Click "Process"
- Ask questions about the document
- Receive AI-generated answers based on document context