File size: 2,394 Bytes
501bc8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Search Quality & Context Improvement Plan

## Goal
Improve the Slackbot's ability to:
1.  **Find relevant documents** even with inexact keywords (typos, spacing).
2.  **Maintain context** across multi-turn conversations (follow-up questions).

## User Review Required
- **Fuzzy Matching Dependency**: Will add `thefuzz` (and `python-Levenshtein` for speed) to `requirements.txt`.
- **Context Logic**: We will modify the `keyword_extraction_prompt` significantly to explicitly ask for "Context" or "Inherited Keywords".

## Proposed Changes

### 1. Improve Search Quality (Fuzzy Search)
**Files**: `requirements.txt`, `search_engine.py`

-   **Install `thefuzz`**: Use Levenshtein distance for metadata matching instead of strict `if keyword in text`.
-   **Exact Match Boost**: Give higher priority or explicit inclusion to exact ID/Title matches if the user mentions them.
-   **Code Change**:
    -   Update `filter_internal_data` and `filter_baymard_data`.
    -   Use `fuzz.partial_ratio` or `fuzz.token_set_ratio` to check match score. Threshold > 70-80.

### 2. Enhance Context Awareness
**Files**: `search_engine.py`

-   **Prompt Engineering**: Update `keyword_extraction_prompt`.
    -   New Instuction: "If the User Query is a follow-up (e.g., 'tell me more about that', 'what about the first one'), EXTRACT keywords from the *previous Assistant response* in Chat History."
    -   Explicitly ask for `primary_topic` from history.
-   **Search Logic Update**:
    -   If the extracted keywords imply a *specific* item (e.g., "RES-001" or a specific title found in history), force a direct ID lookup or high-priority search for that item.

### 3. Verification Plan
-   **Test Case 1 (Search)**: Query "엘리트멤버십" (no space) or "엘리트 맴버십" (typo) -> Should find "엘리트 멤버십...".
-   **Test Case 2 (Context)**:
    -   User: "Search for Membership"
    -   Bot: "Here is [Elite Membership Survey]..."
    -   User: "Tell me more about the low satisfaction group"
    -   **Result**: Bot should know "Elite Membership Survey" is the context and answer using its content.

## Detailed Tasks
1.  [ ] Update `requirements.txt` with `thefuzz`.
2.  [ ] Modify `search_engine.py`:
    -   Import `thefuzz`.
    -   Refactor `filter_...` functions to use fuzzy matching.
    -   Update `keyword_extraction_prompt` to handle history better.
3.  [ ] Deploy & Verify.