kagaju commited on
Commit
4e5eb00
·
2 Parent(s): 125fb755cdac3a

Merge branch 'master' of https://github.com/amt-danielboateng/ai-engineering-project

Browse files
Files changed (6) hide show
  1. .gitignore +2 -1
  2. app.py +3 -3
  3. design-and-evaluation.md +6 -6
  4. evaluation.py +3 -0
  5. ingestion.py +6 -2
  6. requirements.txt +2 -0
.gitignore CHANGED
@@ -4,7 +4,8 @@ venv/
4
  .venv/
5
 
6
  # Project specifics
7
- project-rubrics
 
8
 
9
  # Python
10
  __pycache__/
 
4
  .venv/
5
 
6
  # Project specifics
7
+ project-rubric/
8
+ project-rubrics/
9
 
10
  # Python
11
  __pycache__/
app.py CHANGED
@@ -578,8 +578,8 @@ def get_general_response(user_query: str):
578
 
579
  @st.cache_resource(show_spinner="Loading policy index…")
580
  def init_rag_system():
581
- from langchain_community.embeddings import HuggingFaceEmbeddings
582
- from langchain_community.vectorstores import Chroma
583
  from langchain_openai import ChatOpenAI
584
 
585
  embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
@@ -591,7 +591,7 @@ def init_rag_system():
591
  openai_api_key=OPENROUTER_API_KEY,
592
  model="openrouter/auto",
593
  temperature=0.0,
594
- streaming=True,
595
  )
596
  return retriever, llm
597
 
 
578
 
579
  @st.cache_resource(show_spinner="Loading policy index…")
580
  def init_rag_system():
581
+ from langchain_huggingface import HuggingFaceEmbeddings
582
+ from langchain_chroma import Chroma
583
  from langchain_openai import ChatOpenAI
584
 
585
  embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
 
591
  openai_api_key=OPENROUTER_API_KEY,
592
  model="openrouter/auto",
593
  temperature=0.0,
594
+ max_tokens=512,
595
  )
596
  return retriever, llm
597
 
design-and-evaluation.md CHANGED
@@ -7,15 +7,15 @@
7
  * **Chunking Strategy:** Documents were partitioned using LangChain's `RecursiveCharacterTextSplitter` set to a `chunk_size` of 500 characters and a `chunk_overlap` of 50 characters to guarantee complete coverage of semantic definitions near transition points.
8
 
9
  ## 📊 2. Evaluation Strategy and Results
10
- We evaluated our pipeline across a standardized benchmark test suite of 15 queries covering leave management, security protocols, and operational expenses.
11
 
12
  ### Metric Results Table
13
  | Metric Category | Metric Evaluated | Performance Achieved |
14
  | :--- | :--- | :--- |
15
- | **Answer Quality** | Groundedness Rate | 100.0% |
16
- | **Answer Quality** | Citation Accuracy | 93.3% |
17
- | **System Performance** | $p50$ Latency | 1.14 seconds |
18
- | **System Performance** | $p95$ Latency | 2.45 seconds |
19
 
20
  ### Analysis
21
- Our 100% Groundedness rate indicates that the guardrails injected into our system prompt successfully prevented the model from hallucinating policies outside the given context chunks. The slight drop in Citation Accuracy occurred when a single policy was distributed across multiple consecutive chunks, and the model referenced only the first chronological block.
 
7
  * **Chunking Strategy:** Documents were partitioned using LangChain's `RecursiveCharacterTextSplitter` set to a `chunk_size` of 500 characters and a `chunk_overlap` of 50 characters to guarantee complete coverage of semantic definitions near transition points.
8
 
9
  ## 📊 2. Evaluation Strategy and Results
10
+ We evaluated our pipeline across a standardized benchmark test suite of 20 queries covering PTO, remote work, expenses, security, holidays, parental leave, sick leave, learning & development, performance review, travel, acceptable use, onboarding, health & safety, and code of conduct.
11
 
12
  ### Metric Results Table
13
  | Metric Category | Metric Evaluated | Performance Achieved |
14
  | :--- | :--- | :--- |
15
+ | **Answer Quality** | Groundedness Rate | 95.0% |
16
+ | **Answer Quality** | Citation Accuracy | 95.0% |
17
+ | **System Performance** | $p50$ Latency | 2.69 seconds |
18
+ | **System Performance** | $p95$ Latency | 7.91 seconds |
19
 
20
  ### Analysis
21
+ Our 95% Groundedness and Citation Accuracy rates confirm that the guardrails in the system prompt effectively prevent hallucination. The single failing question (#18 — mandatory onboarding training) failed because the relevant content was split across two chunks from different policy documents (onboarding and code of conduct), causing the model to synthesize an answer that was not fully supported by any single retrieved chunk. The elevated p95 latency (7.91s) is explained by the cold-start on query #1, which triggered model weight loading; subsequent queries settled at a median of 2.69s.
evaluation.py CHANGED
@@ -1,7 +1,10 @@
1
  # evaluation.py
2
  import os
 
3
  import time
4
  import numpy as np
 
 
5
  from app import rag_chain # Import your configured chain from app.py
6
  from langchain_openai import ChatOpenAI
7
  from langchain_core.prompts import ChatPromptTemplate
 
1
  # evaluation.py
2
  import os
3
+ import random
4
  import time
5
  import numpy as np
6
+ random.seed(42)
7
+ np.random.seed(42)
8
  from app import rag_chain # Import your configured chain from app.py
9
  from langchain_openai import ChatOpenAI
10
  from langchain_core.prompts import ChatPromptTemplate
ingestion.py CHANGED
@@ -1,9 +1,13 @@
1
  # ingestion.py
2
  import os
 
 
 
 
3
  from langchain_community.document_loaders import DirectoryLoader, TextLoader
4
  from langchain_text_splitters import RecursiveCharacterTextSplitter
5
- from langchain_community.embeddings import HuggingFaceEmbeddings
6
- from langchain_community.vectorstores import Chroma
7
 
8
  def run_ingestion():
9
  # 1. Load documents from your local corpus
 
1
  # ingestion.py
2
  import os
3
+ import random
4
+ import numpy as np
5
+ random.seed(42)
6
+ np.random.seed(42)
7
  from langchain_community.document_loaders import DirectoryLoader, TextLoader
8
  from langchain_text_splitters import RecursiveCharacterTextSplitter
9
+ from langchain_huggingface import HuggingFaceEmbeddings
10
+ from langchain_chroma import Chroma
11
 
12
  def run_ingestion():
13
  # 1. Load documents from your local corpus
requirements.txt CHANGED
@@ -3,6 +3,8 @@ langchain
3
  langchain-community
4
  langchain-openai
5
  langchain-text-splitters
 
 
6
  chromadb
7
  sentence-transformers
8
  pydantic
 
3
  langchain-community
4
  langchain-openai
5
  langchain-text-splitters
6
+ langchain-huggingface
7
+ langchain-chroma
8
  chromadb
9
  sentence-transformers
10
  pydantic