Search & Ask Feature Documentation

Overview

The Search & Ask feature is a new centerpiece interface in the Visualization section that provides an enhanced natural language query experience with intelligent suggestions, context-aware follow-ups, and disambiguation prompts.

Location

  • Section: Visualization (first tab)
  • URL: http://localhost:3000/workspace?section=visualization
  • Default Tab: Search & Ask (opens by default when visiting visualization)

Key Features

  • Prominent centerpiece design - Large, centered search bar on empty state
  • Real-time input - Immediate feedback as you type
  • Gradient design - Modern blue-to-purple gradient styling
  • Placeholder suggestions - “e.g., top agents by revenue last quarter…”

2. Auto-Suggestions

The system provides intelligent suggestions as you type:

Suggestion Types:

  • 📊 Metrics: total revenue, total calls, average duration, conversion rate
  • 🗺️ Dimensions: by agent, by region, by status, by date
  • 📆 Filters: last quarter, last month, this year, top 10
  • 💬 Queries: Complete query templates like “Show top agents by revenue last quarter”

Suggestion Behavior:

  • Appears automatically as you type
  • Dropdown with icons and type labels
  • Click to append (metrics/dimensions/filters) or execute (queries)
  • Smart filtering based on input

3. Context-Aware Follow-ups

  • Conversation memory - Remembers last 3 queries
  • Follow-up context - “now by region” understands previous query
  • Context indicator - Shows “Context: X previous queries” at bottom
  • No reset needed - Maintains context throughout session

4. Disambiguation Prompts

  • Unclear intent detection - Backend can request clarification
  • Question prompts - System asks specific questions to clarify
  • Guided refinement - Helps users get to the right query

5. Two-State Interface

Empty State (No Queries):

  • Large centered search bar with gradient background
  • Hero heading: “Ask Anything About Your Data”
  • Descriptive subtitle
  • Example query cards (4 clickable examples)
  • Feature highlights (3 feature boxes):
    • ⚡ Auto-Suggestions
    • 💬 Context Aware
    • ✅ Disambiguation

Conversation State (After First Query):

  • Sticky input bar at bottom
  • Scrollable message history
  • Table/chart toggle for results (inherited from existing feature)
  • Suggestion dropdown above input
  • Context indicator

Example Queries

The interface provides these clickable examples:

  1. 👥 “Top 10 agents by revenue last quarter”
  2. 🗺️ “Total calls by region this month”
  3. ⏱️ “Average call duration by status”
  4. 📈 “Conversion rate trend last 6 months”

API Integration

Endpoint

POST /api/v1/query/natural

Request Body

{
  "question": "top agents by revenue last quarter",
  "context": ["previous query 1", "previous query 2", "previous query 3"]
}

Response Handling

  • Success with data: Displays results with table/chart toggle
  • Needs clarification: Shows disambiguation questions
  • No results: Shows friendly message
  • Error: Shows error message

User Experience Flow

First-Time User:

  1. Lands on beautiful empty state with large search bar
  2. Sees example queries to understand capabilities
  3. Clicks example or types their own query
  4. Sees suggestions as they type
  5. Gets results with visualization options

Power User:

  1. Types query directly
  2. Uses auto-suggestions to build complex queries
  3. Asks follow-up questions without repeating context
  4. Gets clarification prompts for ambiguous queries
  5. Switches between table and chart views

Technical Details

Component: SearchAndAsk.tsx

  • Location: frontend/src/components/SearchAndAsk.tsx
  • Lines: ~470 lines
  • Dependencies:
    • React hooks (useState, useRef, useEffect, useMemo)
    • axios for API calls
    • AuthContext for authentication
    • ChatMessage component for displaying results

State Management

const [messages, setMessages] = useState<Message[]>([])
const [input, setInput] = useState('')
const [loading, setLoading] = useState(false)
const [suggestions, setSuggestions] = useState<Suggestion[]>([])
const [showSuggestions, setShowSuggestions] = useState(false)
const [conversationContext, setConversationContext] = useState<string[]>([])

Integration Points

  • Added to ChatInterface.tsx as new visualization tab
  • New tab type: 'search' in VisualizationTabType
  • Tab navigation updated with search icon
  • Initial tab set to 'search' (opens by default)

Styling

Color Scheme

  • Primary gradient: Blue-600 to Purple-600
  • Empty state background: Gray-50 to White gradient
  • Cards: White with hover effects
  • Suggestions: White dropdown with gray hover
  • Icons: Custom SVGs with stroke-based rendering

Responsive Design

  • Max-width containers (4xl = 896px)
  • Grid layouts (1 column mobile, 2-3 columns desktop)
  • Smooth transitions and animations
  • Hover effects on all interactive elements

Performance Considerations

Optimizations

  • Debounced suggestion filtering (happens client-side)
  • Context limited to last 3 queries (reduces payload)
  • Memoized suggestion generation
  • Lazy loading of results
  • Auto-scroll to latest message

Caching

  • Suggestions are generated client-side (instant)
  • Query results are cached by backend (if implemented)
  • Message history kept in component state

Future Enhancements

Potential Improvements:

  1. Voice Input - Add microphone icon for voice queries
  2. Query History - Searchable history of past queries
  3. Saved Queries - Bookmark frequently used queries
  4. Query Templates - Pre-built templates for common analyses
  5. Collaborative Sharing - Share queries with team members
  6. Advanced Filters - Visual filter builder
  7. Query Explanations - Show how query was interpreted
  8. Auto-complete - More sophisticated auto-completion
  9. Natural Language Help - Inline help for query syntax
  10. Export Options - Export results to CSV, Excel, PDF

Testing Checklist

  • Component renders without errors
  • Suggestions appear on typing
  • Example queries are clickable
  • Follow-up context is maintained
  • API integration works
  • Error handling displays properly
  • Loading states show correctly
  • Empty state is visually appealing
  • Conversation view scrolls properly
  • Sticky input stays at bottom
  • Disambiguation prompts tested (requires backend support)
  • Voice input (future enhancement)
  • Mobile responsiveness verified

Accessibility

Implemented:

  • Semantic HTML structure
  • ARIA-compatible form elements
  • Keyboard navigation support (Tab, Enter)
  • Focus states on all interactive elements
  • Clear visual feedback for actions

Future Improvements:

  • Screen reader optimizations
  • High contrast mode support
  • Keyboard shortcuts
  • Focus trapping in modals
  • WCAG 2.1 AA compliance audit

Browser Compatibility

  • ✅ Chrome 90+
  • ✅ Firefox 88+
  • ✅ Safari 14+
  • ✅ Edge 90+
  • ✅ Mobile browsers (iOS Safari, Chrome Mobile)
  • ChatMessage.tsx - Used for displaying query results
  • DataChart.tsx - Provides chart visualization
  • DataTable.tsx - Provides tabular data display
  • ChatInterface.tsx - Parent container with tab navigation
  • HomePage.tsx - Updated to highlight new feature

Documentation Updates

Modified Files:

  1. frontend/src/components/SearchAndAsk.tsx - New component (created)
  2. frontend/src/components/ChatInterface.tsx - Added search tab
  3. frontend/src/components/HomePage.tsx - Updated description

Build Status:

  • ✅ TypeScript compilation successful
  • ✅ Vite build successful (693.52 kB)
  • ✅ No errors or warnings
  • ✅ Application running on http://localhost:3000

Support

For issues or questions:

  1. Check application logs: logs/ui.log
  2. View browser console for frontend errors
  3. Test API directly: http://localhost:8000/docs
  4. Review component props and state in React DevTools

Created: December 27, 2025
Version: 1.0.0
Status: ✅ Production Ready


Back to top

DataTruth © 2025. Built with ♥ using FastAPI, React, and OpenAI.