File size: 2,357 Bytes
40e5eae
 
 
 
5fd4bb2
40e5eae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fd4bb2
ea6f355
 
5fd4bb2
40e5eae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fd4bb2
40e5eae
 
 
 
 
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
"""
Configuration file for RAG System
Contains all settings and parameters for the document processing pipeline
"""
import os
from pathlib import Path
from typing import List

# Project Paths
PROJECT_ROOT = Path(__file__).parent
DOCUMENTS_DIR = PROJECT_ROOT / "documents"
PROCESSED_DOCS_DIR = PROJECT_ROOT / "processed_docs"
CHROMA_DB_DIR = PROJECT_ROOT / "chroma_db"

# Ensure directories exist
DOCUMENTS_DIR.mkdir(exist_ok=True)
PROCESSED_DOCS_DIR.mkdir(exist_ok=True)
CHROMA_DB_DIR.mkdir(exist_ok=True)

# Document Processing Settings
SUPPORTED_FORMATS = [".pdf", ".docx", ".txt", ".md"]

# Text Splitting Configuration
TEXT_SPLITTER_CONFIG = {
    "chunk_size": 1000,
    "chunk_overlap": 200,
    "separators": ["\n\n", "\n", ". ", " ", ""],
    "keep_separator": True,
}

# Embedding Model Configuration
EMBEDDING_MODEL = "all-MiniLM-L6-v2"
EMBEDDING_DIMENSION = 384

# Vector Database Configuration
CHROMA_COLLECTION_NAME = "document_embeddings"
CHROMA_DISTANCE_METRIC = "cosine"

# LLM Configuration - Hugging Face Inference API
# Using Microsoft Phi-3 - officially supported on free tier
HF_MODEL = "microsoft/Phi-3-mini-4k-instruct"  # Officially supported, free, reliable
HF_TOKEN = os.getenv("HF_TOKEN", "")

# Retrieval Configuration
DEFAULT_N_RESULTS = 5
SIMILARITY_THRESHOLD = 0.5

# Prompt Templates
SYSTEM_PROMPT = """You are a helpful assistant. Answer the question based on the context provided.
Be concise and accurate. If you don't know the answer based on the context, say so."""

PROMPT_TEMPLATE = """Context: {context}

Question: {question}

Answer:"""

# Gradio Interface Configuration
GRADIO_CONFIG = {
    "title": "Intelligent Document Q&A System",
    "description": "Ask questions about your documents and get instant answers with source citations.",
    "examples": [
        "How do if-else statements work in Python?",
        "What are the different types of loops in Python?",
        "How do you handle errors in Python?",
        "Explain Python functions with examples",
        "What is object-oriented programming in Python?",
    ],
    "theme": "default",
    "share": True,  # Creates public link for 72 hours  # Set to True to create a public link
}

# Test Document URL (Think Python book)
TEST_DOCUMENT_URL = "https://greenteapress.com/thinkpython/thinkpython.pdf"
TEST_DOCUMENT_NAME = "think_python_guide.pdf"