Spaces:
Running
Running
Commit ·
294d426
1
Parent(s): f7e2e5e
fix: overhaul follow-up detection for conversation memory + add diagnostic logs
Browse files- Dockerfile +1 -1
- src/rag/pipeline.py +24 -7
Dockerfile
CHANGED
|
@@ -15,7 +15,7 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 15 |
|
| 16 |
# Cache-bust: forces Docker to re-copy source code on every build
|
| 17 |
# This ensures HuggingFace always gets the latest code from git
|
| 18 |
-
ARG CACHEBUST=
|
| 19 |
|
| 20 |
# Copy source code
|
| 21 |
COPY src/ ./src/
|
|
|
|
| 15 |
|
| 16 |
# Cache-bust: forces Docker to re-copy source code on every build
|
| 17 |
# This ensures HuggingFace always gets the latest code from git
|
| 18 |
+
ARG CACHEBUST=20260414_5
|
| 19 |
|
| 20 |
# Copy source code
|
| 21 |
COPY src/ ./src/
|
src/rag/pipeline.py
CHANGED
|
@@ -75,25 +75,40 @@ class RAGPipeline:
|
|
| 75 |
history: list[ConversationTurn]
|
| 76 |
) -> str:
|
| 77 |
followup_signals = [
|
| 78 |
-
|
| 79 |
-
"
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
]
|
| 82 |
question_lower = question.lower()
|
|
|
|
|
|
|
|
|
|
| 83 |
is_followup = (
|
| 84 |
-
len(question.split()) <
|
| 85 |
-
any(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
)
|
| 87 |
|
| 88 |
if is_followup and history:
|
| 89 |
last_substantial = ""
|
| 90 |
for turn in reversed(history):
|
| 91 |
-
if turn.role == "user" and len(turn.content.split()) >
|
| 92 |
last_substantial = turn.content
|
| 93 |
break
|
| 94 |
if last_substantial:
|
| 95 |
-
|
|
|
|
|
|
|
| 96 |
|
|
|
|
| 97 |
return question
|
| 98 |
|
| 99 |
def query(
|
|
@@ -179,6 +194,8 @@ class RAGPipeline:
|
|
| 179 |
if not question:
|
| 180 |
raise ValueError("Question cannot be empty")
|
| 181 |
|
|
|
|
|
|
|
| 182 |
total_start = time.time()
|
| 183 |
retrieval_start = time.time()
|
| 184 |
|
|
|
|
| 75 |
history: list[ConversationTurn]
|
| 76 |
) -> str:
|
| 77 |
followup_signals = [
|
| 78 |
+
# pronouns referring to prior context
|
| 79 |
+
"it", "that", "this", "they", "them", "those", "these",
|
| 80 |
+
# conversational follow-ups
|
| 81 |
+
"more", "example", "explain", "clarify", "elaborate",
|
| 82 |
+
"simpler", "simple", "detail", "again", "further",
|
| 83 |
+
# comprehension requests
|
| 84 |
+
"easy", "understand", "meaning", "mean", "summarize",
|
| 85 |
+
"summary", "break down", "eli5", "what about",
|
| 86 |
]
|
| 87 |
question_lower = question.lower()
|
| 88 |
+
question_words = set(question_lower.split())
|
| 89 |
+
|
| 90 |
+
# Use word-boundary matching for single words, substring for phrases
|
| 91 |
is_followup = (
|
| 92 |
+
len(question.split()) < 25 and
|
| 93 |
+
any(
|
| 94 |
+
signal in question_words if " " not in signal
|
| 95 |
+
else signal in question_lower
|
| 96 |
+
for signal in followup_signals
|
| 97 |
+
)
|
| 98 |
)
|
| 99 |
|
| 100 |
if is_followup and history:
|
| 101 |
last_substantial = ""
|
| 102 |
for turn in reversed(history):
|
| 103 |
+
if turn.role == "user" and len(turn.content.split()) > 3:
|
| 104 |
last_substantial = turn.content
|
| 105 |
break
|
| 106 |
if last_substantial:
|
| 107 |
+
combined = f"{last_substantial} {question}"
|
| 108 |
+
logger.info(f"Follow-up detected. Retrieval query: '{combined[:80]}...'")
|
| 109 |
+
return combined
|
| 110 |
|
| 111 |
+
logger.info(f"Standalone query. Retrieval query: '{question[:80]}'")
|
| 112 |
return question
|
| 113 |
|
| 114 |
def query(
|
|
|
|
| 194 |
if not question:
|
| 195 |
raise ValueError("Question cannot be empty")
|
| 196 |
|
| 197 |
+
logger.info(f"stream_query: question='{question[:60]}', history_turns={len(history)}")
|
| 198 |
+
|
| 199 |
total_start = time.time()
|
| 200 |
retrieval_start = time.time()
|
| 201 |
|