Spaces:
Build error
Download CSV_SEARCH_IMPLEMENTATION.md from ashtalksai/agentcourse: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/spaces/ashtalksai/agentcourse/resolve/main/CSV_SEARCH_IMPLEMENTATION.md
- Command line
-
hf download hf://spaces/ashtalksai/agentcourse/CSV_SEARCH_IMPLEMENTATION.md
-
curl -L -o CSV_SEARCH_IMPLEMENTATION.md https://huggingface.co/spaces/ashtalksai/agentcourse/resolve/main/CSV_SEARCH_IMPLEMENTATION.md
A newer version of the Gradio SDK is available: 6.30.0
CSV Knowledge Base Search Implementation
Overview
The agent has been enhanced to prioritize searching a CSV knowledge base before using other tools. This ensures faster, more consistent responses for questions that have been previously answered.
Key Changes Made
1. New CSV Search Tool (agent.py)
- Function:
search_csv_knowledge_base(query: str, top_k: int = 3) - Technology: Uses TF-IDF vectorization and cosine similarity for semantic search
- Features:
- Searches through questions and answers in
supabase_docs.csv - Returns top-k most similar results with similarity scores
- Extracts questions and answers from the content format
- Filters results by minimum similarity threshold (0.1)
- Searches through questions and answers in
2. Modified Agent Workflow (agent.py)
- Priority System: CSV search is now the first tool used for any question
- Enhanced Assistant Function:
- Automatically searches CSV before other tools
- Uses CSV results as foundation for answers
- Falls back to other tools if no relevant CSV results found
- Tool Order: CSV search tool is placed first in the tools list
3. Updated System Prompt (system_prompt.txt)
- New Instructions: Always start with CSV knowledge base search
- Clear Priority: CSV search is explicitly marked as first priority
- Workflow: Updated reasoning process to include CSV search as step 1
4. Dependencies (requirements.txt)
- Added:
scikit-learnfor TF-IDF vectorization and similarity calculations
CSV File Structure
The CSV contains:
- content: Questions and answers in format "Question : [question text] Final answer : [answer]"
- metadata: Task metadata (not used in search)
- embedding: Vector embeddings (not used in current implementation)
How It Works
1. User asks a question
2. Agent automatically searches CSV knowledge base first
csv_result = search_csv_knowledge_base.invoke({
'query': user_question,
'top_k': 3
})
3. If relevant results found:
- Uses CSV information as foundation
- May use additional tools for verification/supplementation
- Provides comprehensive answer
4. If no relevant results found:
- Proceeds with normal tool usage (web search, calculations, etc.)
Benefits
β Faster Responses: No need to search external APIs for known questions β Consistency: Same questions get same answers based on previous knowledge β Cost Efficiency: Reduced API calls to external services β Accuracy: Domain-specific questions answered from verified knowledge base β Fallback: Still uses other tools when CSV doesn't have relevant information
Testing
Test Scripts Created:
test_csv_search.py: Tests CSV search functionality with various queriesdemo_agent_workflow.py: Demonstrates complete agent workflow with CSV priority
Example Results:
- Query: "Finding Nemo fish species invasive" β Found relevant answer about clownfish (34689)
- Query: "AI regulation arXiv June 2022" β Found answer about "egalitarian"
- Query: "What is the capital of France?" β No results, would use other tools
Usage
The agent now automatically prioritizes CSV search. No changes needed in how you interact with it - just ask questions and the agent will:
- Search CSV first
- Use results if found
- Fall back to other tools if needed
- Provide comprehensive answers
This implementation ensures the agent leverages existing knowledge efficiently while maintaining the ability to research new information when needed.