Islam Mamedov commited on
Commit
a29c69c
·
1 Parent(s): b7c8476

Add CI retrieval evaluation gate and lock dependencies

Browse files
Files changed (5) hide show
  1. .github/workflows/ci.yml +58 -0
  2. app.py +1 -1
  3. requirements-lock.txt +124 -0
  4. requirements.txt +5 -0
  5. src/eval.py +35 -8
.github/workflows/ci.yml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Tests and Retrieval Eval
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ concurrency:
15
+ group: ci-${{ github.workflow }}-${{ github.ref }}
16
+ cancel-in-progress: true
17
+
18
+ jobs:
19
+ test-and-evaluate:
20
+ name: Pytest and Recall Gate
21
+ runs-on: ubuntu-latest
22
+ timeout-minutes: 30
23
+
24
+ env:
25
+ TOKENIZERS_PARALLELISM: "false"
26
+ PYTHONUNBUFFERED: "1"
27
+
28
+ steps:
29
+ - name: Check out repository
30
+ uses: actions/checkout@v7
31
+
32
+ - name: Set up Python
33
+ uses: actions/setup-python@v6
34
+ with:
35
+ python-version: "3.11"
36
+ cache: pip
37
+ cache-dependency-path: requirements-lock.txt
38
+
39
+ - name: Install locked dependencies
40
+ run: |
41
+ python -m pip install --upgrade pip
42
+ pip install -r requirements-lock.txt
43
+
44
+ - name: Run unit tests
45
+ run: |
46
+ pytest tests/ -v
47
+
48
+ - name: Build a fresh vector index
49
+ run: |
50
+ rm -rf data/chroma
51
+ python src/index.py
52
+
53
+ - name: Run retrieval evaluation gate
54
+ run: |
55
+ python src/eval.py \
56
+ --mode dense \
57
+ --k 5 \
58
+ --min-recall 0.90
app.py CHANGED
@@ -94,7 +94,7 @@ with st.sidebar:
94
  c4.metric("refusal", "7/7")
95
  st.divider()
96
  st.markdown("[💻 Source & write-up]"
97
- "(https://github.com/Pace200413/codebase-rag)")
98
  if st.button("🗑 Clear conversation", use_container_width=True):
99
  st.session_state.messages = []
100
  st.rerun()
 
94
  c4.metric("refusal", "7/7")
95
  st.divider()
96
  st.markdown("[💻 Source & write-up]"
97
+ "(https://github.com/islam-mamedov/codebase-rag)")
98
  if st.button("🗑 Clear conversation", use_container_width=True):
99
  st.session_state.messages = []
100
  st.rerun()
requirements-lock.txt ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GitPython==3.1.50
2
+ Jinja2==3.1.6
3
+ MarkupSafe==3.0.3
4
+ PyGithub==2.9.1
5
+ PyJWT==2.13.0
6
+ PyNaCl==1.6.2
7
+ PyPika==0.51.1
8
+ PyYAML==6.0.3
9
+ Pygments==2.20.0
10
+ aiohappyeyeballs==2.7.1
11
+ aiohttp==3.14.1
12
+ aiosignal==1.4.0
13
+ altair==6.2.2
14
+ annotated-doc==0.0.4
15
+ annotated-types==0.7.0
16
+ anyio==4.14.1
17
+ attrs==26.1.0
18
+ bcrypt==5.0.0
19
+ blinker==1.9.0
20
+ build==1.5.1
21
+ cachetools==7.1.4
22
+ certifi==2026.6.17
23
+ cffi==2.1.0
24
+ charset-normalizer==3.4.9
25
+ chromadb==1.5.9
26
+ click==8.4.2
27
+ cryptography==49.0.0
28
+ distro==1.9.0
29
+ durationpy==0.10
30
+ filelock==3.29.7
31
+ flatbuffers==25.12.19
32
+ frozenlist==1.8.0
33
+ fsspec==2026.6.0
34
+ gitdb==4.0.12
35
+ googleapis-common-protos==1.75.0
36
+ groq==1.5.0
37
+ grpcio==1.82.1
38
+ h11==0.16.0
39
+ hf-xet==1.5.1
40
+ httpcore==1.0.9
41
+ httptools==0.8.0
42
+ httpx==0.28.1
43
+ huggingface_hub==1.23.0
44
+ idna==3.18
45
+ importlib_resources==7.1.0
46
+ iniconfig==2.3.0
47
+ itsdangerous==2.2.0
48
+ joblib==1.5.3
49
+ jsonschema-specifications==2025.9.1
50
+ jsonschema==4.26.0
51
+ kubernetes==36.0.2
52
+ markdown-it-py==4.2.0
53
+ mdurl==0.1.2
54
+ mmh3==5.2.1
55
+ mpmath==1.3.0
56
+ multidict==6.7.1
57
+ narwhals==2.23.0
58
+ networkx==3.6.1
59
+ numpy==2.4.6
60
+ oauthlib==3.3.1
61
+ onnxruntime==1.27.0
62
+ opentelemetry-api==1.43.0
63
+ opentelemetry-exporter-otlp-proto-common==1.43.0
64
+ opentelemetry-exporter-otlp-proto-grpc==1.43.0
65
+ opentelemetry-proto==1.43.0
66
+ opentelemetry-sdk==1.43.0
67
+ opentelemetry-semantic-conventions==0.64b0
68
+ orjson==3.11.9
69
+ overrides==7.7.0
70
+ packaging==26.2
71
+ pandas==3.0.3
72
+ pillow==12.3.0
73
+ pluggy==1.6.0
74
+ propcache==0.5.2
75
+ protobuf==7.35.1
76
+ pyarrow==25.0.0
77
+ pybase64==1.4.3
78
+ pycparser==3.0
79
+ pydantic-settings==2.14.2
80
+ pydantic==2.13.4
81
+ pydantic_core==2.46.4
82
+ pydeck==0.9.3
83
+ pyproject_hooks==1.2.0
84
+ pytest==9.1.1
85
+ python-dateutil==2.9.0.post0
86
+ python-dotenv==1.2.2
87
+ python-multipart==0.0.32
88
+ rank-bm25==0.2.2
89
+ referencing==0.37.0
90
+ regex==2026.7.10
91
+ requests-oauthlib==2.0.0
92
+ requests==2.34.2
93
+ rich==15.0.0
94
+ rpds-py==2026.6.3
95
+ safetensors==0.8.0
96
+ scikit-learn==1.9.0
97
+ scipy==1.17.1
98
+ sentence-transformers==5.6.0
99
+ shellingham==1.5.4
100
+ six==1.17.0
101
+ smmap==5.0.3
102
+ sniffio==1.3.1
103
+ starlette==1.3.1
104
+ streamlit==1.59.1
105
+ sympy==1.14.0
106
+ tenacity==9.1.4
107
+ threadpoolctl==3.6.0
108
+ tokenizers==0.22.2
109
+ toml==0.10.2
110
+ torch==2.13.0
111
+ tqdm==4.68.4
112
+ transformers==5.13.0
113
+ tree-sitter-python==0.25.0
114
+ tree-sitter==0.26.0
115
+ typer==0.26.8
116
+ typing-inspection==0.4.2
117
+ typing_extensions==4.16.0
118
+ urllib3==2.7.0
119
+ uvicorn==0.51.0
120
+ uvloop==0.22.1
121
+ watchfiles==1.2.0
122
+ websocket-client==1.9.0
123
+ websockets==16.1
124
+ yarl==1.24.2
requirements.txt CHANGED
@@ -3,3 +3,8 @@ chromadb
3
  sentence-transformers
4
  groq
5
  rank-bm25
 
 
 
 
 
 
3
  sentence-transformers
4
  groq
5
  rank-bm25
6
+ python-dotenv
7
+ PyGithub
8
+ tree-sitter
9
+ tree-sitter-python
10
+ pytest
src/eval.py CHANGED
@@ -78,6 +78,12 @@ def main() -> None:
78
  parser.add_argument("--answers", action="store_true",
79
  help="also generate answers and run the LLM judge")
80
  parser.add_argument("--k", type=int, default=K)
 
 
 
 
 
 
81
  args = parser.parse_args()
82
 
83
  items = [json.loads(line)
@@ -102,14 +108,35 @@ def main() -> None:
102
  if not rank:
103
  print(f" [miss] {item['question']}")
104
 
105
- print(f"\n=== Retrieval (mode={args.mode}, k={args.k}) ===")
106
- print(f"recall@{args.k}: {sum(recalls)/len(recalls):.2f} "
107
- f"({int(sum(recalls))}/{len(recalls)})")
108
- print(f"MRR: {sum(mrrs)/len(mrrs):.2f}")
109
-
110
- if not args.answers:
111
- print("\n(retrieval-only run; add --answers for generation metrics)")
112
- return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  # -------- generation + judge metrics --------
115
  import os
 
78
  parser.add_argument("--answers", action="store_true",
79
  help="also generate answers and run the LLM judge")
80
  parser.add_argument("--k", type=int, default=K)
81
+ parser.add_argument(
82
+ "--min-recall",
83
+ type=float,
84
+ default=None,
85
+ help="Exit with code 1 when recall@k is below this threshold.",
86
+ )
87
  args = parser.parse_args()
88
 
89
  items = [json.loads(line)
 
108
  if not rank:
109
  print(f" [miss] {item['question']}")
110
 
111
+ if not recalls:
112
+ raise RuntimeError("The evaluation set contains no answerable questions.")
113
+
114
+ recall_at_k = sum(recalls) / len(recalls)
115
+ mrr = sum(mrrs) / len(mrrs)
116
+
117
+ print(f"\n=== Retrieval (mode={args.mode}, k={args.k}) ===")
118
+ print(
119
+ f"recall@{args.k}: {recall_at_k:.2f} "
120
+ f"({int(sum(recalls))}/{len(recalls)})"
121
+ )
122
+ print(f"MRR: {mrr:.2f}")
123
+
124
+ if args.min_recall is not None:
125
+ if recall_at_k < args.min_recall:
126
+ print(
127
+ f"\n[gate] FAIL: recall@{args.k}={recall_at_k:.4f} "
128
+ f"is below the required {args.min_recall:.4f}"
129
+ )
130
+ raise SystemExit(1)
131
+
132
+ print(
133
+ f"\n[gate] PASS: recall@{args.k}={recall_at_k:.4f} "
134
+ f"meets the required {args.min_recall:.4f}"
135
+ )
136
+
137
+ if not args.answers:
138
+ print("\n(retrieval-only run; add --answers for generation metrics)")
139
+ return
140
 
141
  # -------- generation + judge metrics --------
142
  import os