Spaces:
Sleeping
Sleeping
Cleanup: remove experimental logs and temporary debug scripts
Browse files- Dockerfile.openenv +0 -27
- debug_gemini.py +0 -20
- debug_models.py +0 -16
- debug_tokens.py +0 -21
- final_audit_utf8.log +0 -69
- final_boost.log +0 -0
- final_boost_2.log +0 -0
- final_boost_3.log +0 -0
- last_err.log +0 -0
- last_err_utf8.log +0 -71
- last_fail.log +0 -0
- last_out.log +0 -0
- last_out_utf8.log +0 -9
- last_pass.log +0 -0
- output.log +0 -0
- output_utf8.log +0 -4
- server_err.log +0 -0
- server_out.log +0 -0
- simple_rag_gc.py +0 -104
- stderr.log +0 -0
- stderr_utf8.log +0 -63
- stdout.log +0 -0
- stdout_utf8.log +0 -3
- test_env.py +0 -64
- test_reward_logic.py +0 -44
- test_tasks.py +0 -74
- verify_logic.py +0 -29
Dockerfile.openenv
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
FROM python:3.11-slim
|
| 2 |
-
|
| 3 |
-
# Set environment variables
|
| 4 |
-
ENV PYTHONUNBUFFERED=1
|
| 5 |
-
ENV PYTHONPATH=/app
|
| 6 |
-
|
| 7 |
-
WORKDIR /app
|
| 8 |
-
|
| 9 |
-
# Install system dependencies
|
| 10 |
-
RUN apt-get update && apt-get install -y \
|
| 11 |
-
build-essential \
|
| 12 |
-
curl \
|
| 13 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
-
|
| 15 |
-
# Copy and install Python dependencies
|
| 16 |
-
COPY requirements.txt .
|
| 17 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 18 |
-
|
| 19 |
-
# Copy the environment code
|
| 20 |
-
COPY context_pruning_env ./context_pruning_env
|
| 21 |
-
|
| 22 |
-
# Expose the default OpenEnv port
|
| 23 |
-
EXPOSE 7860
|
| 24 |
-
|
| 25 |
-
# Command to run the environment server (standardized OpenEnv entrypoint)
|
| 26 |
-
# In a real environment, you'd use a server wrapper mapping Gymnasium resets/steps to API calls.
|
| 27 |
-
CMD ["uvicorn", "context_pruning_env.server.app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_gemini.py
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from openai import OpenAI
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
|
| 5 |
-
load_dotenv()
|
| 6 |
-
|
| 7 |
-
client = OpenAI(
|
| 8 |
-
api_key=os.environ.get("GOOGLE_API_KEY"),
|
| 9 |
-
base_url=os.environ.get("API_BASE_URL")
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
try:
|
| 13 |
-
response = client.chat.completions.create(
|
| 14 |
-
model=os.environ.get("MODEL_NAME", "gemini-1.5-flash"),
|
| 15 |
-
messages=[{"role": "user", "content": "Say hello world."}],
|
| 16 |
-
max_tokens=100
|
| 17 |
-
)
|
| 18 |
-
print("SUCCESS:", response.choices[0].message.content)
|
| 19 |
-
except Exception as e:
|
| 20 |
-
print("FAILED:", str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_models.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from google import genai
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
|
| 5 |
-
load_dotenv()
|
| 6 |
-
API_KEY = os.environ.get("GEMINI_API_KEY") or os.environ.get("GOOGLE_API_KEY")
|
| 7 |
-
print(f"API_KEY starting with: {API_KEY[:10]}...")
|
| 8 |
-
|
| 9 |
-
client = genai.Client(api_key=API_KEY)
|
| 10 |
-
|
| 11 |
-
try:
|
| 12 |
-
print("Listing models...")
|
| 13 |
-
for model in client.models.list():
|
| 14 |
-
print(f"- {model.name}")
|
| 15 |
-
except Exception as e:
|
| 16 |
-
print(f"Error listing models: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_tokens.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
from rag_gc_env.environment import RAGGCEnvironment
|
| 2 |
-
from rag_gc_env.models import RAGGCAction
|
| 3 |
-
|
| 4 |
-
def test_medium():
|
| 5 |
-
env = RAGGCEnvironment()
|
| 6 |
-
obs = env.reset(task_name="medium_token_compression")
|
| 7 |
-
print(f"Initial tokens: {obs.token_count}, budget: {obs.token_budget}")
|
| 8 |
-
|
| 9 |
-
obs = env.step(RAGGCAction(verb="delete", document_id="m2"))
|
| 10 |
-
print(f"After delete m2: {obs.token_count}")
|
| 11 |
-
|
| 12 |
-
obs = env.step(RAGGCAction(verb="summarize", document_id="m0"))
|
| 13 |
-
print(f"After summarize m0: {obs.token_count}")
|
| 14 |
-
|
| 15 |
-
if obs.token_count > obs.token_budget:
|
| 16 |
-
print("BUG: token_count still above budget!")
|
| 17 |
-
else:
|
| 18 |
-
print("OK: token_count below budget.")
|
| 19 |
-
|
| 20 |
-
if __name__ == "__main__":
|
| 21 |
-
test_medium()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final_audit_utf8.log
DELETED
|
@@ -1,69 +0,0 @@
|
|
| 1 |
-
python : HTTP Request: POST http
|
| 2 |
-
s://generativelanguage.googleapi
|
| 3 |
-
s.com/v1beta/openai/chat/complet
|
| 4 |
-
ions "HTTP/1.1 404 Not Found"
|
| 5 |
-
At line:1 char:45
|
| 6 |
-
+ ... v:GOOGLE_API_KEY ; python
|
| 7 |
-
inference.py > final_audit.log
|
| 8 |
-
2>&1; cat fi ...
|
| 9 |
-
+ ~~~~~~~
|
| 10 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 11 |
-
~~~
|
| 12 |
-
+ CategoryInfo :
|
| 13 |
-
NotS pecified: (HTTP
|
| 14 |
-
Request: P... 404 Not
|
| 15 |
-
Found":String) [], Rem
|
| 16 |
-
oteException
|
| 17 |
-
+ FullyQualifiedErrorId :
|
| 18 |
-
Nati veCommandError
|
| 19 |
-
|
| 20 |
-
Inference Error: Error code:
|
| 21 |
-
404 - [{'error': {'code': 404,
|
| 22 |
-
'message':
|
| 23 |
-
'models/gemini-1.5-flash is not
|
| 24 |
-
found for API version v1main,
|
| 25 |
-
or is not supported for
|
| 26 |
-
generateContent. Call
|
| 27 |
-
ListModels to see the list of
|
| 28 |
-
available models and their
|
| 29 |
-
supported methods.', 'status':
|
| 30 |
-
'NOT_FOUND'}}]
|
| 31 |
-
HTTP Request: POST https://gener
|
| 32 |
-
ativelanguage.googleapis.com/v1b
|
| 33 |
-
eta/openai/chat/completions
|
| 34 |
-
"HTTP/1.1 404 Not Found"
|
| 35 |
-
Inference Error: Error code:
|
| 36 |
-
404 - [{'error': {'code': 404,
|
| 37 |
-
'message':
|
| 38 |
-
'models/gemini-1.5-flash is not
|
| 39 |
-
found for API version v1main,
|
| 40 |
-
or is not supported for
|
| 41 |
-
generateContent. Call
|
| 42 |
-
ListModels to see the list of
|
| 43 |
-
available models and their
|
| 44 |
-
supported methods.', 'status':
|
| 45 |
-
'NOT_FOUND'}}]
|
| 46 |
-
HTTP Request: POST https://gener
|
| 47 |
-
ativelanguage.googleapis.com/v1b
|
| 48 |
-
eta/openai/chat/completions
|
| 49 |
-
"HTTP/1.1 404 Not Found"
|
| 50 |
-
Inference Error: Error code:
|
| 51 |
-
404 - [{'error': {'code': 404,
|
| 52 |
-
'message':
|
| 53 |
-
'models/gemini-1.5-flash is not
|
| 54 |
-
found for API version v1main,
|
| 55 |
-
or is not supported for
|
| 56 |
-
generateContent. Call
|
| 57 |
-
ListModels to see the list of
|
| 58 |
-
available models and their
|
| 59 |
-
supported methods.', 'status':
|
| 60 |
-
'NOT_FOUND'}}]
|
| 61 |
-
[START] task=noise_purge env=contextprune model=gemini-1.5-flash step=0 action=null reward=0.0 done=false success=null score=0.0
|
| 62 |
-
[STEP] task=noise_purge env=contextprune model=gemini-1.5-flash step=1 action=[1, 1] reward=0.70 done=true error=null success=false steps=1 score=0.50 rewards=0.70
|
| 63 |
-
[END] task=noise_purge score=0.50 success=false
|
| 64 |
-
[START] task=dedupe_arena env=contextprune model=gemini-1.5-flash step=0 action=null reward=0.0 done=false success=null score=0.0
|
| 65 |
-
[STEP] task=dedupe_arena env=contextprune model=gemini-1.5-flash step=1 action=[1, 1, 1] reward=0.70 done=true error=null success=false steps=1 score=0.50 rewards=0.70
|
| 66 |
-
[END] task=dedupe_arena score=0.50 success=false
|
| 67 |
-
[START] task=signal_extract env=contextprune model=gemini-1.5-flash step=0 action=null reward=0.0 done=false success=null score=0.0
|
| 68 |
-
[STEP] task=signal_extract env=contextprune model=gemini-1.5-flash step=1 action=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] reward=0.70 done=true error=null success=false steps=1 score=0.10 rewards=0.70
|
| 69 |
-
[END] task=signal_extract score=0.10 success=false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final_boost.log
DELETED
|
Binary file (5.5 kB)
|
|
|
final_boost_2.log
DELETED
|
Binary file (6.77 kB)
|
|
|
final_boost_3.log
DELETED
|
Binary file (6.77 kB)
|
|
|
last_err.log
DELETED
|
Binary file (3.91 kB)
|
|
|
last_err_utf8.log
DELETED
|
@@ -1,71 +0,0 @@
|
|
| 1 |
-
python : D:\Projects\RAG\context
|
| 2 |
-
_pruning_env\models.py:10:
|
| 3 |
-
PydanticDeprecatedSince20:
|
| 4 |
-
`min_items` is deprecated and
|
| 5 |
-
will be removed, use
|
| 6 |
-
`min_length` instead.
|
| 7 |
-
Deprecated in Pydantic V2.0 to
|
| 8 |
-
be removed in V3.0. See
|
| 9 |
-
Pydantic V2 Migration Guide at h
|
| 10 |
-
ttps://errors.pydantic.dev/2.12/
|
| 11 |
-
migration/
|
| 12 |
-
At line:1 char:1
|
| 13 |
-
+ python inference.py >
|
| 14 |
-
last_out.log 2> last_err.log;
|
| 15 |
-
Get-Content last_ ...
|
| 16 |
-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 17 |
-
~~~~~~~~~~~~~~~~~~~~
|
| 18 |
-
+ CategoryInfo :
|
| 19 |
-
NotS pecified:
|
| 20 |
-
(D:\Projects\RAG...2
|
| 21 |
-
.12/migration/:String) [], Rem
|
| 22 |
-
oteException
|
| 23 |
-
+ FullyQualifiedErrorId :
|
| 24 |
-
Nati veCommandError
|
| 25 |
-
|
| 26 |
-
mask: List[int] = Field(
|
| 27 |
-
HTTP Request: POST https://gener
|
| 28 |
-
ativelanguage.googleapis.com/v1b
|
| 29 |
-
eta/openai/chat/completions
|
| 30 |
-
"HTTP/1.1 404 Not Found"
|
| 31 |
-
Inference Error: Error code:
|
| 32 |
-
404 - [{'error': {'code': 404,
|
| 33 |
-
'message':
|
| 34 |
-
'models/gemini-3-flash is not
|
| 35 |
-
found for API version v1main,
|
| 36 |
-
or is not supported for
|
| 37 |
-
generateContent. Call
|
| 38 |
-
ListModels to see the list of
|
| 39 |
-
available models and their
|
| 40 |
-
supported methods.', 'status':
|
| 41 |
-
'NOT_FOUND'}}]
|
| 42 |
-
HTTP Request: POST https://gener
|
| 43 |
-
ativelanguage.googleapis.com/v1b
|
| 44 |
-
eta/openai/chat/completions
|
| 45 |
-
"HTTP/1.1 404 Not Found"
|
| 46 |
-
Inference Error: Error code:
|
| 47 |
-
404 - [{'error': {'code': 404,
|
| 48 |
-
'message':
|
| 49 |
-
'models/gemini-3-flash is not
|
| 50 |
-
found for API version v1main,
|
| 51 |
-
or is not supported for
|
| 52 |
-
generateContent. Call
|
| 53 |
-
ListModels to see the list of
|
| 54 |
-
available models and their
|
| 55 |
-
supported methods.', 'status':
|
| 56 |
-
'NOT_FOUND'}}]
|
| 57 |
-
HTTP Request: POST https://gener
|
| 58 |
-
ativelanguage.googleapis.com/v1b
|
| 59 |
-
eta/openai/chat/completions
|
| 60 |
-
"HTTP/1.1 404 Not Found"
|
| 61 |
-
Inference Error: Error code:
|
| 62 |
-
404 - [{'error': {'code': 404,
|
| 63 |
-
'message':
|
| 64 |
-
'models/gemini-3-flash is not
|
| 65 |
-
found for API version v1main,
|
| 66 |
-
or is not supported for
|
| 67 |
-
generateContent. Call
|
| 68 |
-
ListModels to see the list of
|
| 69 |
-
available models and their
|
| 70 |
-
supported methods.', 'status':
|
| 71 |
-
'NOT_FOUND'}}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_fail.log
DELETED
|
Binary file (3.3 kB)
|
|
|
last_out.log
DELETED
|
Binary file (2.16 kB)
|
|
|
last_out_utf8.log
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
[START] task=noise_purge env=contextprune model=gemini-3-flash step=0 action=null reward=0.0 done=false success=null score=0.0
|
| 2 |
-
[STEP] task=noise_purge env=contextprune model=gemini-3-flash step=1 action=[1, 1] reward=0.70 done=true error=null success=false steps=1 score=0.50 rewards=0.70
|
| 3 |
-
[END] task=noise_purge score=0.50 success=false
|
| 4 |
-
[START] task=dedupe_arena env=contextprune model=gemini-3-flash step=0 action=null reward=0.0 done=false success=null score=0.0
|
| 5 |
-
[STEP] task=dedupe_arena env=contextprune model=gemini-3-flash step=1 action=[1, 1, 1] reward=0.70 done=true error=null success=false steps=1 score=0.50 rewards=0.70
|
| 6 |
-
[END] task=dedupe_arena score=0.50 success=false
|
| 7 |
-
[START] task=signal_extract env=contextprune model=gemini-3-flash step=0 action=null reward=0.0 done=false success=null score=0.0
|
| 8 |
-
[STEP] task=signal_extract env=contextprune model=gemini-3-flash step=1 action=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] reward=0.70 done=true error=null success=false steps=1 score=0.10 rewards=0.70
|
| 9 |
-
[END] task=signal_extract score=0.10 success=false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_pass.log
DELETED
|
Binary file (2.19 kB)
|
|
|
output.log
DELETED
|
Binary file (528 Bytes)
|
|
|
output_utf8.log
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
easy_irrelevant_removal score= 1.0 trace= ['reset', 'delete:d1', 'submit:None']
|
| 2 |
-
medium_token_compression score= 1.0 trace= ['reset', 'delete:m2', 'summarize:m0', 'submit:None']
|
| 3 |
-
hard_contradiction_removal score= 1.0 trace= ['reset', 'delete:h1', 'submit:None']
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server_err.log
DELETED
|
Binary file (1.16 kB)
|
|
|
server_out.log
DELETED
|
File without changes
|
simple_rag_gc.py
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
🚀 Simple RAG Garbage Collector
|
| 3 |
-
A beginner-friendly tool to optimize context by removing irrelevant documents.
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
def count_words(text_list):
|
| 7 |
-
"""Counts total words across all documents in the list."""
|
| 8 |
-
total = 0
|
| 9 |
-
for text in text_list:
|
| 10 |
-
total += len(text.split())
|
| 11 |
-
return total
|
| 12 |
-
|
| 13 |
-
def optimize_context(query, documents):
|
| 14 |
-
"""
|
| 15 |
-
Cleans up the documents by:
|
| 16 |
-
1. Checking if they contain keywords from the query.
|
| 17 |
-
2. Truncating long documents to save space.
|
| 18 |
-
"""
|
| 19 |
-
query_keywords = query.lower().split()
|
| 20 |
-
optimized_docs = []
|
| 21 |
-
removed_count = 0
|
| 22 |
-
|
| 23 |
-
# Analyze each document
|
| 24 |
-
for doc in documents:
|
| 25 |
-
is_relevant = False
|
| 26 |
-
|
| 27 |
-
# Simple relevance check: Does the doc contain any query word?
|
| 28 |
-
for word in query_keywords:
|
| 29 |
-
if word in doc.lower():
|
| 30 |
-
is_relevant = True
|
| 31 |
-
break
|
| 32 |
-
|
| 33 |
-
if is_relevant:
|
| 34 |
-
# Optionally shorten documents longer than 30 words
|
| 35 |
-
words = doc.split()
|
| 36 |
-
if len(words) > 30:
|
| 37 |
-
shortened_doc = " ".join(words[:30]) + "..."
|
| 38 |
-
optimized_docs.append(shortened_doc)
|
| 39 |
-
else:
|
| 40 |
-
optimized_docs.append(doc)
|
| 41 |
-
else:
|
| 42 |
-
removed_count += 1
|
| 43 |
-
|
| 44 |
-
return optimized_docs, removed_count
|
| 45 |
-
|
| 46 |
-
def main():
|
| 47 |
-
"""Main loop for the terminal-based interactive system."""
|
| 48 |
-
print("--- Welcome to the RAG Garbage Collector ---")
|
| 49 |
-
|
| 50 |
-
while True:
|
| 51 |
-
# 1. Get User Query
|
| 52 |
-
user_query = input("\nEnter your search query (e.g., 'Paris capital'): ").strip()
|
| 53 |
-
if not user_query:
|
| 54 |
-
print("Please enter a valid query.")
|
| 55 |
-
continue
|
| 56 |
-
|
| 57 |
-
# 2. Get Documents
|
| 58 |
-
print("\nEnter your documents one by one. Type 'done' when finished.")
|
| 59 |
-
original_docs = []
|
| 60 |
-
while True:
|
| 61 |
-
doc_input = input("> ").strip()
|
| 62 |
-
if doc_input.lower() == 'done':
|
| 63 |
-
break
|
| 64 |
-
if doc_input:
|
| 65 |
-
original_docs.append(doc_input)
|
| 66 |
-
|
| 67 |
-
if not original_docs:
|
| 68 |
-
print("No documents provided. Ending this session.")
|
| 69 |
-
else:
|
| 70 |
-
# 3. Calculate Stats Before
|
| 71 |
-
words_before = count_words(original_docs)
|
| 72 |
-
print("\n" + "="*40)
|
| 73 |
-
print("BEFORE OPTIMIZATION")
|
| 74 |
-
print(f"Total Documents: {len(original_docs)}")
|
| 75 |
-
print(f"Total Word Count: {words_before}")
|
| 76 |
-
print("="*40)
|
| 77 |
-
|
| 78 |
-
# 4. Run Optimization
|
| 79 |
-
final_docs, removed = optimize_context(user_query, original_docs)
|
| 80 |
-
|
| 81 |
-
# 5. Calculate Stats After
|
| 82 |
-
words_after = count_words(final_docs)
|
| 83 |
-
print("\nAFTER OPTIMIZATION")
|
| 84 |
-
print(f"Documents Kept: {len(final_docs)}")
|
| 85 |
-
print(f"Documents Removed: {removed}")
|
| 86 |
-
print(f"Final Word Count: {words_after}")
|
| 87 |
-
print(f"Efficiency: {words_before - words_after} words saved!")
|
| 88 |
-
print("="*40)
|
| 89 |
-
|
| 90 |
-
# 6. Show Final Context
|
| 91 |
-
print("\nFINAL CONTEXT:")
|
| 92 |
-
if not final_docs:
|
| 93 |
-
print("[No relevant documents found!]")
|
| 94 |
-
for i, d in enumerate(final_docs, 1):
|
| 95 |
-
print(f"{i}. {d}")
|
| 96 |
-
|
| 97 |
-
# 7. Repeat Check
|
| 98 |
-
choice = input("\nDo you want to try another query? (yes/no): ").strip().lower()
|
| 99 |
-
if choice != 'yes':
|
| 100 |
-
print("Goodbye! Thanks for using the RAG Garbage Collector.")
|
| 101 |
-
break
|
| 102 |
-
|
| 103 |
-
if __name__ == "__main__":
|
| 104 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stderr.log
DELETED
|
Binary file (3.9 kB)
|
|
|
stderr_utf8.log
DELETED
|
@@ -1,63 +0,0 @@
|
|
| 1 |
-
python : D:\Projects\RAG\context_pr
|
| 2 |
-
uning_env\models.py:10:
|
| 3 |
-
PydanticDeprecatedSince20:
|
| 4 |
-
`min_items` is deprecated and will
|
| 5 |
-
be removed, use `min_length`
|
| 6 |
-
instead. Deprecated in Pydantic
|
| 7 |
-
V2.0 to be removed in V3.0. See
|
| 8 |
-
Pydantic V2 Migration Guide at http
|
| 9 |
-
s://errors.pydantic.dev/2.12/migrat
|
| 10 |
-
ion/
|
| 11 |
-
At line:1 char:1
|
| 12 |
-
+ python inference.py 2> stderr.log
|
| 13 |
-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 14 |
-
+ CategoryInfo : NotS
|
| 15 |
-
pecified: (D:\Projects\RAG...2
|
| 16 |
-
.12/migration/:String) [], Rem
|
| 17 |
-
oteException
|
| 18 |
-
+ FullyQualifiedErrorId : Nati
|
| 19 |
-
veCommandError
|
| 20 |
-
|
| 21 |
-
mask: List[int] = Field(
|
| 22 |
-
HTTP Request: POST https://generati
|
| 23 |
-
velanguage.googleapis.com/v1beta/op
|
| 24 |
-
enai/chat/completions "HTTP/1.1
|
| 25 |
-
404 Not Found"
|
| 26 |
-
Inference Error: Error code: 404 -
|
| 27 |
-
[{'error': {'code': 404,
|
| 28 |
-
'message':
|
| 29 |
-
'models/gemini-1.5-flash is not
|
| 30 |
-
found for API version v1main, or
|
| 31 |
-
is not supported for
|
| 32 |
-
generateContent. Call ListModels
|
| 33 |
-
to see the list of available
|
| 34 |
-
models and their supported
|
| 35 |
-
methods.', 'status': 'NOT_FOUND'}}]
|
| 36 |
-
HTTP Request: POST https://generati
|
| 37 |
-
velanguage.googleapis.com/v1beta/op
|
| 38 |
-
enai/chat/completions "HTTP/1.1
|
| 39 |
-
404 Not Found"
|
| 40 |
-
Inference Error: Error code: 404 -
|
| 41 |
-
[{'error': {'code': 404,
|
| 42 |
-
'message':
|
| 43 |
-
'models/gemini-1.5-flash is not
|
| 44 |
-
found for API version v1main, or
|
| 45 |
-
is not supported for
|
| 46 |
-
generateContent. Call ListModels
|
| 47 |
-
to see the list of available
|
| 48 |
-
models and their supported
|
| 49 |
-
methods.', 'status': 'NOT_FOUND'}}]
|
| 50 |
-
HTTP Request: POST https://generati
|
| 51 |
-
velanguage.googleapis.com/v1beta/op
|
| 52 |
-
enai/chat/completions "HTTP/1.1
|
| 53 |
-
404 Not Found"
|
| 54 |
-
Inference Error: Error code: 404 -
|
| 55 |
-
[{'error': {'code': 404,
|
| 56 |
-
'message':
|
| 57 |
-
'models/gemini-1.5-flash is not
|
| 58 |
-
found for API version v1main, or
|
| 59 |
-
is not supported for
|
| 60 |
-
generateContent. Call ListModels
|
| 61 |
-
to see the list of available
|
| 62 |
-
models and their supported
|
| 63 |
-
methods.', 'status': 'NOT_FOUND'}}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stdout.log
DELETED
|
Binary file (1.05 kB)
|
|
|
stdout_utf8.log
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
task=noise_purge env=contextprune model=gemini-1.5-flash step=1 action=[1, 1] reward=0.70 done=true error=null success=false steps=1 score=0.50 rewards=0.70
|
| 2 |
-
task=dedupe_arena env=contextprune model=gemini-1.5-flash step=1 action=[1, 1, 1] reward=0.70 done=true error=null success=false steps=1 score=0.50 rewards=0.70
|
| 3 |
-
task=signal_extract env=contextprune model=gemini-1.5-flash step=1 action=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] reward=0.70 done=true error=null success=false steps=1 score=0.10 rewards=0.70
|
|
|
|
|
|
|
|
|
|
|
|
test_env.py
DELETED
|
@@ -1,64 +0,0 @@
|
|
| 1 |
-
import unittest
|
| 2 |
-
from unittest.mock import MagicMock
|
| 3 |
-
from context_pruning_env.env import ContextPruningEnv
|
| 4 |
-
from context_pruning_env.models import PruningAction, ChunkItem
|
| 5 |
-
|
| 6 |
-
class TestContextPruningEnv(unittest.TestCase):
|
| 7 |
-
def setUp(self):
|
| 8 |
-
# Create env and mock the loader to avoid HF dataset download
|
| 9 |
-
self.env = ContextPruningEnv(squad_split="train")
|
| 10 |
-
self.env.loader = MagicMock()
|
| 11 |
-
|
| 12 |
-
# Mock episode data: 1 Gold, 4 Noise
|
| 13 |
-
self.mock_question = "What color is the sky?"
|
| 14 |
-
self.mock_chunks = [
|
| 15 |
-
("The sky appears blue due to Rayleigh scattering.", True),
|
| 16 |
-
("Grass is usually green.", False),
|
| 17 |
-
("Pizza is delicious.", False),
|
| 18 |
-
("Computers process binary data.", False),
|
| 19 |
-
("Antarctica is cold.", False)
|
| 20 |
-
]
|
| 21 |
-
self.env.loader.get_episode.return_value = (self.mock_question, self.mock_chunks)
|
| 22 |
-
|
| 23 |
-
def test_reset(self):
|
| 24 |
-
obs = self.env.reset()
|
| 25 |
-
self.assertEqual(obs.question, self.mock_question)
|
| 26 |
-
self.assertEqual(len(obs.chunks), 5)
|
| 27 |
-
self.assertFalse(obs.done)
|
| 28 |
-
|
| 29 |
-
def test_step_keep_gold(self):
|
| 30 |
-
self.env.reset()
|
| 31 |
-
# Gold is at index 0
|
| 32 |
-
# Action: Keep all
|
| 33 |
-
action = PruningAction(mask=[1, 1, 1, 1, 1])
|
| 34 |
-
obs = self.env.step(action)
|
| 35 |
-
|
| 36 |
-
self.assertTrue(obs.done)
|
| 37 |
-
# Accuracy bonus + tokens saved (0 in this case)
|
| 38 |
-
self.assertEqual(obs.reward, 10.0)
|
| 39 |
-
self.assertIn("Success", obs.message)
|
| 40 |
-
|
| 41 |
-
def test_step_prune_gold(self):
|
| 42 |
-
self.env.reset()
|
| 43 |
-
# Gold is at index 0
|
| 44 |
-
# Action: Prune gold, keep others
|
| 45 |
-
action = PruningAction(mask=[0, 1, 1, 1, 1])
|
| 46 |
-
obs = self.env.step(action)
|
| 47 |
-
|
| 48 |
-
self.assertTrue(obs.done)
|
| 49 |
-
self.assertEqual(obs.reward, -20.0)
|
| 50 |
-
self.assertIn("Failure", obs.message)
|
| 51 |
-
|
| 52 |
-
def test_step_efficiency(self):
|
| 53 |
-
self.env.reset()
|
| 54 |
-
# Gold is at index 0
|
| 55 |
-
# Action: Keep gold, prune others
|
| 56 |
-
action = PruningAction(mask=[1, 0, 0, 0, 0])
|
| 57 |
-
obs = self.env.step(action)
|
| 58 |
-
|
| 59 |
-
self.assertTrue(obs.done)
|
| 60 |
-
self.assertGreater(obs.reward, 10.0) # Accuracy (10) + Efficiency (>0)
|
| 61 |
-
self.assertIn("Success", obs.message)
|
| 62 |
-
|
| 63 |
-
if __name__ == "__main__":
|
| 64 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_reward_logic.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
| 1 |
-
from rag_gc_env.environment import RAGGCEnvironment
|
| 2 |
-
from rag_gc_env.models import RAGGCAction
|
| 3 |
-
|
| 4 |
-
def test_reward_logic():
|
| 5 |
-
env = RAGGCEnvironment()
|
| 6 |
-
|
| 7 |
-
# Test 1: Deleting irrelevant document should be POSITIVE
|
| 8 |
-
print("\n--- Test 1: Deleting irrelevant (d1) in Easy Task ---")
|
| 9 |
-
obs = env.reset(task_name="easy_irrelevant_removal")
|
| 10 |
-
tokens_before = obs.token_count
|
| 11 |
-
obs = env.step(RAGGCAction(verb="delete", document_id="d1"))
|
| 12 |
-
print(f"Tokens: {tokens_before} -> {obs.token_count} (Saved {tokens_before - obs.token_count})")
|
| 13 |
-
print(f"Step Reward for deleting d1: {obs.reward}")
|
| 14 |
-
if obs.reward > 0:
|
| 15 |
-
print("PASS: Positive reward for deletion.")
|
| 16 |
-
else:
|
| 17 |
-
print("FAIL: Reward should be positive.")
|
| 18 |
-
|
| 19 |
-
# Test 2: Summarizing to save tokens should be POSITIVE
|
| 20 |
-
print("\n--- Test 2: Summarizing (m0) in Medium Task ---")
|
| 21 |
-
obs = env.reset(task_name="medium_token_compression")
|
| 22 |
-
tokens_before = obs.token_count
|
| 23 |
-
obs = env.step(RAGGCAction(verb="summarize", document_id="m0"))
|
| 24 |
-
print(f"Tokens: {tokens_before} -> {obs.token_count} (Saved {tokens_before - obs.token_count})")
|
| 25 |
-
print(f"Step Reward for summarizing m0: {obs.reward}")
|
| 26 |
-
if obs.reward > 0:
|
| 27 |
-
print("PASS: Positive reward for summarization.")
|
| 28 |
-
else:
|
| 29 |
-
print("FAIL: Reward should be positive (was previously negative).")
|
| 30 |
-
|
| 31 |
-
# Test 3: Over budget penalty should be reflected in reward
|
| 32 |
-
print("\n--- Test 3: Over budget penalty in Medium Task ---")
|
| 33 |
-
obs = env.reset(task_name="medium_token_compression")
|
| 34 |
-
print(f"Current Tokens: {obs.token_count} (Budget: {obs.token_budget})")
|
| 35 |
-
# budget is 120, total is 190. over by 70.
|
| 36 |
-
obs = env.step(RAGGCAction(verb="keep", document_id="m1"))
|
| 37 |
-
print(f"Reward with budget penalty: {obs.reward}")
|
| 38 |
-
if obs.reward < -5:
|
| 39 |
-
print("PASS: Budget penalty correctly reflected in step reward.")
|
| 40 |
-
else:
|
| 41 |
-
print("FAIL: Budget penalty missing or too low.")
|
| 42 |
-
|
| 43 |
-
if __name__ == "__main__":
|
| 44 |
-
test_reward_logic()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_tasks.py
DELETED
|
@@ -1,74 +0,0 @@
|
|
| 1 |
-
import pytest
|
| 2 |
-
from unittest.mock import MagicMock
|
| 3 |
-
from context_pruning_env.env import ContextPruningEnv
|
| 4 |
-
from context_pruning_env.models import ContextAction
|
| 5 |
-
|
| 6 |
-
@pytest.fixture
|
| 7 |
-
def env():
|
| 8 |
-
# Setup env and mock data loader
|
| 9 |
-
env = ContextPruningEnv(squad_split="train")
|
| 10 |
-
env.loader = MagicMock()
|
| 11 |
-
return env
|
| 12 |
-
|
| 13 |
-
def test_noise_filter(env):
|
| 14 |
-
# Mock: 1 Gold (index 2), 4 Noise
|
| 15 |
-
mock_chunks = [
|
| 16 |
-
{"content": "noise 1", "is_gold": False, "is_duplicate": False},
|
| 17 |
-
{"content": "noise 2", "is_gold": False, "is_duplicate": False},
|
| 18 |
-
{"content": "gold chunk", "is_gold": True, "is_duplicate": False},
|
| 19 |
-
{"content": "noise 3", "is_gold": False, "is_duplicate": False},
|
| 20 |
-
{"content": "noise 4", "is_gold": False, "is_duplicate": False},
|
| 21 |
-
]
|
| 22 |
-
env.loader.get_episode.return_value = ("Question?", mock_chunks)
|
| 23 |
-
|
| 24 |
-
env.reset(task_name="noise_filter")
|
| 25 |
-
|
| 26 |
-
# Correct Action: Keep only gold at index 2
|
| 27 |
-
action = ContextAction(mask=[0, 0, 1, 0, 0])
|
| 28 |
-
obs = env.step(action)
|
| 29 |
-
assert obs.reward == 1.0
|
| 30 |
-
assert "Perfect" in obs.message
|
| 31 |
-
|
| 32 |
-
def test_deduplication(env):
|
| 33 |
-
# Mock: 2 Gold (indices 0, 3), 3 Noise
|
| 34 |
-
mock_chunks = [
|
| 35 |
-
{"content": "gold chunk", "is_gold": True, "is_duplicate": False},
|
| 36 |
-
{"content": "noise 1", "is_gold": False, "is_duplicate": False},
|
| 37 |
-
{"content": "noise 2", "is_gold": False, "is_duplicate": False},
|
| 38 |
-
{"content": "gold chunk duplicate", "is_gold": True, "is_duplicate": True},
|
| 39 |
-
{"content": "noise 3", "is_gold": False, "is_duplicate": False},
|
| 40 |
-
]
|
| 41 |
-
env.loader.get_episode.return_value = ("Question?", mock_chunks)
|
| 42 |
-
|
| 43 |
-
env.reset(task_name="deduplication")
|
| 44 |
-
|
| 45 |
-
# Incorrect Action: Keep both gold
|
| 46 |
-
action = ContextAction(mask=[1, 0, 0, 1, 0])
|
| 47 |
-
obs = env.step(action)
|
| 48 |
-
assert obs.reward < 1.0
|
| 49 |
-
assert "Duplicates" in obs.message
|
| 50 |
-
|
| 51 |
-
# Correct Action: Keep exactly 1 gold
|
| 52 |
-
env.reset(task_name="deduplication")
|
| 53 |
-
action = ContextAction(mask=[1, 0, 0, 0, 0])
|
| 54 |
-
obs = env.step(action)
|
| 55 |
-
assert obs.reward == 1.0
|
| 56 |
-
|
| 57 |
-
def test_sentence_distillation(env):
|
| 58 |
-
# Mock: 1 Gold (index 0), 4 related noise
|
| 59 |
-
mock_chunks = [
|
| 60 |
-
{"content": "gold sentence", "is_gold": True, "is_duplicate": False},
|
| 61 |
-
{"content": "noise sentence 1", "is_gold": False, "is_duplicate": False},
|
| 62 |
-
{"content": "noise sentence 2", "is_gold": False, "is_duplicate": False},
|
| 63 |
-
{"content": "noise sentence 3", "is_gold": False, "is_duplicate": False},
|
| 64 |
-
{"content": "noise sentence 4", "is_gold": False, "is_duplicate": False},
|
| 65 |
-
]
|
| 66 |
-
env.loader.get_episode.return_value = ("Question?", mock_chunks)
|
| 67 |
-
|
| 68 |
-
env.reset(task_name="sentence_distillation")
|
| 69 |
-
|
| 70 |
-
# Correct Action: Keep only gold, prune the rest
|
| 71 |
-
action = ContextAction(mask=[1, 0, 0, 0, 0])
|
| 72 |
-
obs = env.step(action)
|
| 73 |
-
assert obs.reward == 1.0
|
| 74 |
-
assert "Sharp distillation" in obs.message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify_logic.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import json
|
| 3 |
-
from context_pruning_env.env import ContextPruningEnv
|
| 4 |
-
from context_pruning_env.models import ContextAction
|
| 5 |
-
|
| 6 |
-
def verify_logic():
|
| 7 |
-
env = ContextPruningEnv()
|
| 8 |
-
task = "signal_extract"
|
| 9 |
-
obs = env.reset(task_name=task)
|
| 10 |
-
|
| 11 |
-
# DUMMY OPTIMAL ACTION: Keep only the gold chunk
|
| 12 |
-
# In signal_extract, exactly 1 chunk is gold.
|
| 13 |
-
mask = []
|
| 14 |
-
for c in env._state.chunks:
|
| 15 |
-
mask.append(1 if c.is_gold else 0)
|
| 16 |
-
|
| 17 |
-
print(f"DEBUG: Logic Verification with Optimal Mask: {mask}")
|
| 18 |
-
action = ContextAction(mask=mask)
|
| 19 |
-
obs = env.step(action)
|
| 20 |
-
|
| 21 |
-
score = obs.metadata.get("eval_score", 0.0)
|
| 22 |
-
print(f"[LOGIC_VERIFY] task={task} score={score:.2f}")
|
| 23 |
-
if score > 0.85:
|
| 24 |
-
print("SUCCESS: Environment logic is correctly optimizing.")
|
| 25 |
-
else:
|
| 26 |
-
print("FAILURE: Environment logic is still biased.")
|
| 27 |
-
|
| 28 |
-
if __name__ == "__main__":
|
| 29 |
-
verify_logic()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|