Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- README.md +5 -5
- assets/Architecture_diagram.jpeg +0 -0
- inference.py +49 -7
- memory/lessons_learned.json +30 -0
- openenv.yaml +12 -12
- server/kb_seed.json +84 -8
- server/rag_optimizer_environment.py +31 -24
README.md
CHANGED
|
@@ -162,14 +162,14 @@ The environment tests agents across three progressively demanding task distribut
|
|
| 162 |
**The Vector Issue:** The base contains heavily overlapping parameters (competing versions of legacy and modern timeline protocols).
|
| 163 |
**System Goal:** Autonomously survey the semantic differences, deduce the temporal conflict, and execute `delete_document` sweeps to purge vector hallucination triggers.
|
| 164 |
|
| 165 |
-
### Level II:
|
| 166 |
-
**The Vector Issue:** The KB contains overlapping incident narratives mixed with distractor engineering notes, causing retrieval ambiguity.
|
| 167 |
-
**System Goal:** Deduplicate noisy/partial incident content so retrieval consistently surfaces the clean resolution document at rank 1.
|
| 168 |
-
|
| 169 |
-
### Level III: Syntactic Splintering (The Monolith)
|
| 170 |
**The Vector Issue:** Extreme embedding decay caused by disparate conceptual structures compacted under a single referential document. This represents the well-known "PDF chunk wash-out" phenomenon.
|
| 171 |
**System Goal:** Methodically `read` the extensive parent block, temporarily cache the semantic context limits, and utilize rapid consecutive `update_document` calls to mechanically splinter and redistribute the knowledge logic across multiple fine-grained nodes.
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
---
|
| 174 |
|
| 175 |
## 5. Inference Baseline Sandbox
|
|
|
|
| 162 |
**The Vector Issue:** The base contains heavily overlapping parameters (competing versions of legacy and modern timeline protocols).
|
| 163 |
**System Goal:** Autonomously survey the semantic differences, deduce the temporal conflict, and execute `delete_document` sweeps to purge vector hallucination triggers.
|
| 164 |
|
| 165 |
+
### Level II: Syntactic Splintering
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
**The Vector Issue:** Extreme embedding decay caused by disparate conceptual structures compacted under a single referential document. This represents the well-known "PDF chunk wash-out" phenomenon.
|
| 167 |
**System Goal:** Methodically `read` the extensive parent block, temporarily cache the semantic context limits, and utilize rapid consecutive `update_document` calls to mechanically splinter and redistribute the knowledge logic across multiple fine-grained nodes.
|
| 168 |
|
| 169 |
+
### Level III: Duplicate Purge
|
| 170 |
+
**The Vector Issue:** The KB contains overlapping FastAPI routing docs where legacy `@app.route()` guidance competes against the correct current `@app.get()` / `@app.post()` pattern with Pydantic v2.
|
| 171 |
+
**System Goal:** Deduplicate legacy routing docs so retrieval consistently ranks the correct current routing reference at #1.
|
| 172 |
+
|
| 173 |
---
|
| 174 |
|
| 175 |
## 5. Inference Baseline Sandbox
|
assets/Architecture_diagram.jpeg
CHANGED
|
|
inference.py
CHANGED
|
@@ -113,6 +113,40 @@ def _clamp_score(value: float) -> float:
|
|
| 113 |
return value
|
| 114 |
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
def run_task_episode(
|
| 117 |
env: RagOptimizerEnvClient,
|
| 118 |
llm_client: OpenAI,
|
|
@@ -156,14 +190,22 @@ def run_task_episode(
|
|
| 156 |
error_msg = "null"
|
| 157 |
|
| 158 |
try:
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
response_text = completion.choices[0].message.content or ""
|
| 166 |
-
action_data =
|
| 167 |
|
| 168 |
# Normalize fields if model returns lists instead of strings
|
| 169 |
for field in ("doc_id", "text", "metadata_key", "metadata_value"):
|
|
|
|
| 113 |
return value
|
| 114 |
|
| 115 |
|
| 116 |
+
def _extract_json_object(text: str) -> dict:
|
| 117 |
+
"""Extract a JSON object from model output that may include extra text."""
|
| 118 |
+
if not text:
|
| 119 |
+
raise ValueError("empty model response")
|
| 120 |
+
|
| 121 |
+
raw = text.strip()
|
| 122 |
+
try:
|
| 123 |
+
return json.loads(raw)
|
| 124 |
+
except Exception:
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
# Common markdown fence wrapper
|
| 128 |
+
if "```" in raw:
|
| 129 |
+
parts = raw.split("```")
|
| 130 |
+
for part in parts:
|
| 131 |
+
candidate = part.strip()
|
| 132 |
+
if candidate.lower().startswith("json"):
|
| 133 |
+
candidate = candidate[4:].strip()
|
| 134 |
+
if candidate.startswith("{") and candidate.endswith("}"):
|
| 135 |
+
try:
|
| 136 |
+
return json.loads(candidate)
|
| 137 |
+
except Exception:
|
| 138 |
+
pass
|
| 139 |
+
|
| 140 |
+
# Fallback: take substring between first '{' and last '}'
|
| 141 |
+
start = raw.find("{")
|
| 142 |
+
end = raw.rfind("}")
|
| 143 |
+
if start != -1 and end != -1 and end > start:
|
| 144 |
+
candidate = raw[start:end + 1]
|
| 145 |
+
return json.loads(candidate)
|
| 146 |
+
|
| 147 |
+
raise ValueError("no JSON object found in model response")
|
| 148 |
+
|
| 149 |
+
|
| 150 |
def run_task_episode(
|
| 151 |
env: RagOptimizerEnvClient,
|
| 152 |
llm_client: OpenAI,
|
|
|
|
| 190 |
error_msg = "null"
|
| 191 |
|
| 192 |
try:
|
| 193 |
+
try:
|
| 194 |
+
completion = llm_client.chat.completions.create(
|
| 195 |
+
model=MODEL_NAME,
|
| 196 |
+
messages=messages,
|
| 197 |
+
response_format={"type": "json_object"},
|
| 198 |
+
max_tokens=1000,
|
| 199 |
+
)
|
| 200 |
+
except Exception:
|
| 201 |
+
# Some OpenAI-compatible providers may not enforce response_format.
|
| 202 |
+
completion = llm_client.chat.completions.create(
|
| 203 |
+
model=MODEL_NAME,
|
| 204 |
+
messages=messages,
|
| 205 |
+
max_tokens=1000,
|
| 206 |
+
)
|
| 207 |
response_text = completion.choices[0].message.content or ""
|
| 208 |
+
action_data = _extract_json_object(response_text)
|
| 209 |
|
| 210 |
# Normalize fields if model returns lists instead of strings
|
| 211 |
for field in ("doc_id", "text", "metadata_key", "metadata_value"):
|
memory/lessons_learned.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"task": "medium",
|
| 4 |
+
"lesson": "The agent should have prioritized deleting documents with relevant metadata, such as \"doc_incident_raw\", \"doc_incident_partial\", and \"doc_incident_resolved\", which contained meaningful information, instead of sequentially deleting the distractor documents."
|
| 5 |
+
},
|
| 6 |
+
{
|
| 7 |
+
"task": "easy",
|
| 8 |
+
"lesson": "The agent should have added the \"subcategory\": \"api_framework\" metadata to documents \"fastapi_7\", \"fastapi_8\", \"fastapi_9\", and \"fastapi_10\" to increase the consistency of the knowledge base and ultimately achieve a higher reward."
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"task": "medium",
|
| 12 |
+
"lesson": "The agent should have taken a more targeted approach to document deletion, prioritizing the removal of irrelevant documents while preserving key incident reports, such as \"doc_incident_raw\", \"doc_incident_partial\", and \"doc_incident_resolved\", to maximize the reward and achieve the task objective."
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"task": "medium",
|
| 16 |
+
"lesson": "The agent should have performed a \"merge_document\" action to combine the relevant information from \"doc_incident_raw\" and \"doc_incident_partial\" into \"doc_incident_resolved\", instead of deleting distractor documents and reading \"doc_incident_resolved\", to achieve a higher reward and successfully"
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"task": "medium",
|
| 20 |
+
"lesson": ""
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"task": "medium",
|
| 24 |
+
"lesson": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"task": "medium",
|
| 28 |
+
"lesson": ""
|
| 29 |
+
}
|
| 30 |
+
]
|
openenv.yaml
CHANGED
|
@@ -11,24 +11,24 @@ environment:
|
|
| 11 |
state: "/state/{session_id}"
|
| 12 |
tasks:
|
| 13 |
- id: easy
|
| 14 |
-
name: "
|
| 15 |
-
description: "
|
| 16 |
reward_range: [0.01, 0.99]
|
| 17 |
grader: "rag_optimizer.server.grader:grade_easy"
|
| 18 |
- id: medium
|
| 19 |
-
name: "
|
| 20 |
-
description:
|
| 21 |
-
Multi-doc deduplication. KB contains 3 overlapping incident reports
|
| 22 |
-
for the same outage - one raw, one partial, one with the correct
|
| 23 |
-
resolution - plus 20 engineering distractors. Agent must delete the
|
| 24 |
-
noisy duplicates so retrieval surfaces the clean resolution doc at
|
| 25 |
-
rank 1. Reward improves continuously as noise is removed; no binary
|
| 26 |
-
metadata gate.
|
| 27 |
reward_range: [0.01, 0.99]
|
| 28 |
grader: "rag_optimizer.server.grader:grade_medium"
|
| 29 |
- id: hard
|
| 30 |
-
name: "
|
| 31 |
-
description:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
reward_range: [0.01, 0.99]
|
| 33 |
grader: "rag_optimizer.server.grader:grade_hard"
|
| 34 |
agent:
|
|
|
|
| 11 |
state: "/state/{session_id}"
|
| 12 |
tasks:
|
| 13 |
- id: easy
|
| 14 |
+
name: "Contamination Purging"
|
| 15 |
+
description: "Purge contradictory or low-value documents so retrieval surfaces clean, high-signal references."
|
| 16 |
reward_range: [0.01, 0.99]
|
| 17 |
grader: "rag_optimizer.server.grader:grade_easy"
|
| 18 |
- id: medium
|
| 19 |
+
name: "Syntactic Splintering"
|
| 20 |
+
description: "Break down the monolithic onboarding blob into multiple granular chunks."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
reward_range: [0.01, 0.99]
|
| 22 |
grader: "rag_optimizer.server.grader:grade_medium"
|
| 23 |
- id: hard
|
| 24 |
+
name: "Duplicate Purge"
|
| 25 |
+
description: >
|
| 26 |
+
Multi-doc deduplication for framework drift. KB contains 3 overlapping
|
| 27 |
+
FastAPI routing docs: two legacy variants with incorrect @app.route()
|
| 28 |
+
guidance and one correct current doc using @app.get()/@app.post() and
|
| 29 |
+
Pydantic v2, plus distractors. Agent must delete noisy legacy docs so
|
| 30 |
+
retrieval surfaces the correct current doc at rank 1. Reward improves
|
| 31 |
+
continuously as noise is removed; no binary metadata gate.
|
| 32 |
reward_range: [0.01, 0.99]
|
| 33 |
grader: "rag_optimizer.server.grader:grade_hard"
|
| 34 |
agent:
|
server/kb_seed.json
CHANGED
|
@@ -123,20 +123,96 @@
|
|
| 123 |
}
|
| 124 |
},
|
| 125 |
"medium": {
|
| 126 |
-
"
|
| 127 |
-
"text": "
|
| 128 |
"metadata": {}
|
| 129 |
},
|
| 130 |
-
"
|
| 131 |
-
"text": "The
|
| 132 |
"metadata": {}
|
| 133 |
},
|
| 134 |
-
"
|
| 135 |
-
"text": "
|
| 136 |
"metadata": {}
|
| 137 |
},
|
| 138 |
-
"
|
| 139 |
-
"text": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
"metadata": {}
|
| 141 |
}
|
| 142 |
},
|
|
|
|
| 123 |
}
|
| 124 |
},
|
| 125 |
"medium": {
|
| 126 |
+
"doc_incident_raw": {
|
| 127 |
+
"text": "Initial incident report logged by the on-call engineer at 09:10 AM. Users are reporting that a critical frontend action button on the dashboard is missing entirely. The issue appears intermittent across sessions but is reproducible in staging. Alongside this, monitoring dashboards show elevated database latency, particularly on read-heavy endpoints. There is uncertainty whether these issues are related or coincidental. Some engineers suspect a rendering issue, while others believe degraded backend performance may be delaying UI state hydration. No mitigation has been applied yet. Logs show sporadic 401 errors on certain API endpoints, but it is unclear if this is connected. The incident has been escalated to both frontend and backend teams. Investigation is ongoing, and further updates will be provided as more data becomes available.",
|
| 128 |
"metadata": {}
|
| 129 |
},
|
| 130 |
+
"doc_incident_partial": {
|
| 131 |
+
"text": "Follow-up report after initial investigation. The frontend team attempted a quick fix by updating CSS rules related to button visibility, assuming a rendering regression. However, this did not resolve the missing button issue in production. Further debugging indicates that the button component is conditionally rendered based on an API response, which is occasionally failing. Backend logs show consistent 401 errors from an internal service endpoint. The backend team suspects that an expired API key might be causing authentication failures, leading to incomplete data being sent to the frontend. Database latency has slightly improved but is still above baseline. Teams are now focusing on authentication layers and service communication. No permanent fix has been deployed yet.",
|
| 132 |
"metadata": {}
|
| 133 |
},
|
| 134 |
+
"doc_incident_resolved": {
|
| 135 |
+
"text": "Final post-mortem of the production outage. The root cause was determined to be two independent but overlapping issues. The missing frontend button was caused by a regression in styling, which was resolved by updating CSS stylesheet rules that incorrectly hid the component under certain conditions. Separately, the 401 authentication errors were traced to an expired API key used by an internal service. This was resolved through API key rotation on Tuesday, restoring proper authentication flow. Once both fixes were deployed, system behavior returned to normal. Additional safeguards have been implemented, including monitoring for API key expiration and stricter validation of frontend rendering conditions. Teams have documented the incident and updated runbooks to prevent recurrence.",
|
| 136 |
"metadata": {}
|
| 137 |
},
|
| 138 |
+
"doc_eng_1": {
|
| 139 |
+
"text": "Architecture decision record discussing migration of frontend styling systems. The team evaluated moving from traditional CSS modules to a utility-first framework. During testing, inconsistencies were observed in how legacy components handled conditional rendering tied to API key permissions. Some endpoints returned 401 errors when tokens expired, which affected component visibility. The decision was to incrementally migrate styles while keeping backward compatibility. Engineers also noted that rotation policies for API keys should be standardized across services. This ADR highlights the importance of aligning frontend behavior with backend authentication systems.",
|
| 140 |
+
"metadata": {}
|
| 141 |
+
},
|
| 142 |
+
"doc_eng_2": {
|
| 143 |
+
"text": "Sprint planning notes for Q3 engineering cycle. The frontend team proposed improvements to UI consistency, including refactoring CSS classes and removing deprecated styles. Meanwhile, the backend team raised concerns about API key rotation policies, noting that expired keys had caused minor 401 errors in staging. The team agreed to prioritize monitoring improvements and better alerting mechanisms. No direct incidents were reported, but proactive measures were discussed to prevent future disruptions.",
|
| 144 |
+
"metadata": {}
|
| 145 |
+
},
|
| 146 |
+
"doc_eng_3": {
|
| 147 |
+
"text": "Git commit summary describing updates to authentication middleware. The change introduced stricter validation for API keys, rejecting requests with expired credentials. This led to an increase in 401 errors during testing, which was expected. The frontend team was notified to handle these errors gracefully. Additionally, minor CSS updates were included to improve button alignment across browsers. The commit emphasizes security improvements and better error handling.",
|
| 148 |
+
"metadata": {}
|
| 149 |
+
},
|
| 150 |
+
"doc_eng_4": {
|
| 151 |
+
"text": "Benchmark report analyzing frontend performance under load. Tests revealed that CSS rendering time increased slightly when large stylesheets were loaded. API key validation latency also contributed to overall response times. However, no critical failures were observed. Engineers recommended optimizing CSS delivery and caching API key validation results to reduce overhead.",
|
| 152 |
+
"metadata": {}
|
| 153 |
+
},
|
| 154 |
+
"doc_eng_5": {
|
| 155 |
+
"text": "Internal memo discussing API key lifecycle management. The document outlines best practices for rotation, including automated renewal and monitoring for expiration. It also highlights cases where expired keys caused 401 errors in non-critical services. Frontend teams are advised to display fallback UI elements when authentication fails.",
|
| 156 |
+
"metadata": {}
|
| 157 |
+
},
|
| 158 |
+
"doc_eng_6": {
|
| 159 |
+
"text": "Design document for a new frontend component library. The library standardizes CSS usage and ensures consistent styling across applications. It also integrates with backend authentication systems, handling API key validation states. Engineers noted that improper handling of 401 errors could lead to missing UI elements.",
|
| 160 |
+
"metadata": {}
|
| 161 |
+
},
|
| 162 |
+
"doc_eng_7": {
|
| 163 |
+
"text": "Post-deployment analysis of a minor release. The update included CSS refactoring and improvements to API key validation logic. Some users experienced temporary 401 errors due to delayed key rotation, but no major outages occurred. The team plans to improve synchronization between frontend and backend systems.",
|
| 164 |
+
"metadata": {}
|
| 165 |
+
},
|
| 166 |
+
"doc_eng_8": {
|
| 167 |
+
"text": "Engineering notes on improving observability. The team added logging for API key validation failures and CSS rendering issues. This helps identify cases where frontend components fail to display due to backend errors. Alerts are configured for repeated 401 errors.",
|
| 168 |
+
"metadata": {}
|
| 169 |
+
},
|
| 170 |
+
"doc_eng_9": {
|
| 171 |
+
"text": "Technical review of authentication flows. The system uses API keys for service-to-service communication. Engineers identified that inconsistent rotation schedules could lead to 401 errors. Frontend applications must handle these gracefully to avoid user confusion.",
|
| 172 |
+
"metadata": {}
|
| 173 |
+
},
|
| 174 |
+
"doc_eng_10": {
|
| 175 |
+
"text": "Frontend refactor proposal focusing on CSS modularization. The goal is to reduce conflicts between styles and improve maintainability. The proposal also includes handling API key-based feature flags, ensuring components render correctly even when authentication states change.",
|
| 176 |
+
"metadata": {}
|
| 177 |
+
},
|
| 178 |
+
"doc_eng_11": {
|
| 179 |
+
"text": "System reliability report highlighting minor incidents. Some services experienced 401 errors due to expired API keys. CSS updates were deployed to improve UI consistency. No major user impact was observed.",
|
| 180 |
+
"metadata": {}
|
| 181 |
+
},
|
| 182 |
+
"doc_eng_12": {
|
| 183 |
+
"text": "Developer onboarding guide explaining authentication mechanisms. New engineers are taught how API keys are generated, rotated, and validated. The guide also covers frontend error handling for 401 responses.",
|
| 184 |
+
"metadata": {}
|
| 185 |
+
},
|
| 186 |
+
"doc_eng_13": {
|
| 187 |
+
"text": "Performance optimization notes for frontend rendering. Engineers experimented with reducing CSS bundle sizes and improving load times. API key validation overhead was also analyzed.",
|
| 188 |
+
"metadata": {}
|
| 189 |
+
},
|
| 190 |
+
"doc_eng_14": {
|
| 191 |
+
"text": "Security audit report identifying risks in API key management. The audit found that some keys were not rotated regularly, leading to potential 401 errors. Recommendations include automated rotation and better monitoring.",
|
| 192 |
+
"metadata": {}
|
| 193 |
+
},
|
| 194 |
+
"doc_eng_15": {
|
| 195 |
+
"text": "Release notes for version 2.3. The update includes CSS fixes and improved API key validation. Some minor 401 errors were expected during rollout.",
|
| 196 |
+
"metadata": {}
|
| 197 |
+
},
|
| 198 |
+
"doc_eng_16": {
|
| 199 |
+
"text": "Backend architecture review discussing authentication services. API key validation is centralized, but frontend teams must handle errors properly. CSS-related UI issues were noted in previous releases.",
|
| 200 |
+
"metadata": {}
|
| 201 |
+
},
|
| 202 |
+
"doc_eng_17": {
|
| 203 |
+
"text": "Incident simulation exercise documenting response to API key expiration. Teams practiced handling 401 errors and updating frontend components. CSS adjustments were part of the simulation.",
|
| 204 |
+
"metadata": {}
|
| 205 |
+
},
|
| 206 |
+
"doc_eng_18": {
|
| 207 |
+
"text": "Code review feedback on frontend components. Reviewers noted inconsistent CSS usage and lack of error handling for API key failures. Improvements were suggested.",
|
| 208 |
+
"metadata": {}
|
| 209 |
+
},
|
| 210 |
+
"doc_eng_19": {
|
| 211 |
+
"text": "Infrastructure planning document for scaling authentication services. API key rotation policies are discussed, along with frontend implications of 401 errors.",
|
| 212 |
+
"metadata": {}
|
| 213 |
+
},
|
| 214 |
+
"doc_eng_20": {
|
| 215 |
+
"text": "QA testing report covering authentication and UI scenarios. Test cases include expired API keys, resulting in 401 errors, and CSS rendering issues affecting frontend components.",
|
| 216 |
"metadata": {}
|
| 217 |
}
|
| 218 |
},
|
server/rag_optimizer_environment.py
CHANGED
|
@@ -69,37 +69,44 @@ class RagOptimizerEnvironment(Environment):
|
|
| 69 |
]
|
| 70 |
|
| 71 |
elif task_id == "medium":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
self.kb = {
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
"
|
|
|
|
| 76 |
},
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
"
|
|
|
|
| 80 |
},
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
"
|
|
|
|
| 84 |
},
|
| 85 |
}
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
| 89 |
"metadata": {}
|
| 90 |
}
|
| 91 |
self.test_suite = [
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
{"query": "
|
| 95 |
-
"target_concept": "
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
elif task_id == "hard":
|
| 99 |
-
self.test_suite = [
|
| 100 |
-
{"query": "Which entity bankruptcy was the climax of the disaster?", "target_concept": "bankruptcy of Lehman Brothers"},
|
| 101 |
-
{"query": "What types of collateralized assets lost their worth?", "target_concept": "Mortgage-backed securities"},
|
| 102 |
-
{"query": "Who did predatory lenders primarily go after?", "target_concept": "low-income homebuyers"}
|
| 103 |
]
|
| 104 |
|
| 105 |
self._rebuild_cache()
|
|
@@ -266,4 +273,4 @@ class RagOptimizerEnvironment(Environment):
|
|
| 266 |
|
| 267 |
@property
|
| 268 |
def state(self) -> State:
|
| 269 |
-
return self._state
|
|
|
|
| 69 |
]
|
| 70 |
|
| 71 |
elif task_id == "medium":
|
| 72 |
+
self.kb = deepcopy(self.seed_data["hard"])
|
| 73 |
+
self.test_suite = [
|
| 74 |
+
{"query": "Which entity bankruptcy was the climax of the disaster?", "target_concept": "bankruptcy of Lehman Brothers"},
|
| 75 |
+
{"query": "What types of collateralized assets lost their worth?", "target_concept": "Mortgage-backed securities"},
|
| 76 |
+
{"query": "Who did predatory lenders primarily go after?", "target_concept": "low-income homebuyers"}
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
elif task_id == "hard":
|
| 80 |
self.kb = {
|
| 81 |
+
# v1 — legacy, wrong routing syntax, poisons retrieval rank for v3
|
| 82 |
+
"fastapi_routing_v1": {
|
| 83 |
+
"text": "FastAPI routing uses @app.route() decorator similar to Flask. Define routes with methods=['GET','POST']. Pydantic v1 handles all schema validation.",
|
| 84 |
+
"metadata": {"version": "legacy"}
|
| 85 |
},
|
| 86 |
+
# v2 — also legacy, still wrong syntax, further dilutes correct doc
|
| 87 |
+
"fastapi_routing_v2": {
|
| 88 |
+
"text": "FastAPI routes are defined using @app.route() with type hints added. Validation is done through Pydantic v1 models attached to each endpoint.",
|
| 89 |
+
"metadata": {"version": "legacy"}
|
| 90 |
},
|
| 91 |
+
# v3 — CORRECT current doc, must survive and rank #1 after purge
|
| 92 |
+
"fastapi_routing_v3": {
|
| 93 |
+
"text": "FastAPI uses @app.get(), @app.post() and other HTTP method decorators for routing. It defaults to Pydantic v2 for request and response validation.",
|
| 94 |
+
"metadata": {"version": "current"}
|
| 95 |
},
|
| 96 |
}
|
| 97 |
+
# 15 generic distractors — low semantic overlap, provide ranking noise
|
| 98 |
+
for i in range(15):
|
| 99 |
+
self.kb[f"doc_distractor_{i}"] = {
|
| 100 |
+
"text": f"General web framework note {i}: always use async handlers for better throughput in high-traffic services.",
|
| 101 |
"metadata": {}
|
| 102 |
}
|
| 103 |
self.test_suite = [
|
| 104 |
+
# v1 and v2 both contain @app.route() which competes semantically with v3
|
| 105 |
+
# Deleting v1 and v2 pushes v3 to rank 1 → each delete gives a visible reward jump
|
| 106 |
+
{"query": "How are routes defined in FastAPI?",
|
| 107 |
+
"target_concept": "@app.get(), @app.post() decorators"},
|
| 108 |
+
{"query": "Which Pydantic version does FastAPI v2 use by default?",
|
| 109 |
+
"target_concept": "defaults to Pydantic v2"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
]
|
| 111 |
|
| 112 |
self._rebuild_cache()
|
|
|
|
| 273 |
|
| 274 |
@property
|
| 275 |
def state(self) -> State:
|
| 276 |
+
return self._state
|