Ask Feature Guide

The Ask feature is a powerful RAG (Retrieval Augmented Generation) system that enables natural language conversations with your code documentation. It combines advanced retrieval techniques with AI to provide accurate, contextual answers about your codebase.

What is the Ask Feature?

The Ask feature transforms your static documentation into an interactive knowledge base where you can:
  • Ask natural questions about your code, APIs, and documentation
  • Get contextual answers with relevant code snippets and explanations
  • Maintain conversation history for follow-up questions
  • Access real-time streaming responses for immediate feedback
  • Query programmatically via API for integration into other tools

RAG Architecture

The Ask feature uses Retrieval Augmented Generation (RAG) to combine the best of both worlds: precise information retrieval from your docs with the natural language capabilities of large language models.

How RAG Works with Code

1. Document Indexing

When your wiki is generated, DeepWikiOpen creates semantic embeddings of your documentation:

2. Query Processing

When you ask a question, the system:
  1. Converts your question into a semantic embedding
  2. Searches the vector database for relevant documentation chunks
  3. Retrieves contextual information from multiple sources
  4. Generates a comprehensive answer using the retrieved context
// 1. Question embedding
const questionEmbedding = await embedQuery(userQuestion);

// 2. Similarity search
const relevantChunks = await vectorStore.similaritySearch(
  questionEmbedding,
  { k: 5, threshold: 0.7 }
);

// 3. Context preparation
const context = relevantChunks.map(chunk => ({
  content: chunk.content,
  source: chunk.metadata.source,
  score: chunk.score
}));

// 4. Response generation
const response = await generateResponse(userQuestion, context);

Using the Ask Interface

Basic Question Interface

The Ask feature provides an intuitive chat interface in your generated wiki:
Ask Feature Interface

Conversation Flow

1

Ask Your Question

Type your question in natural language in the Ask input field
How do I authenticate users in this API?
2

Real-time Processing

Watch as the system processes your query with streaming responses
Searching documentation... ⚡
Found 3 relevant sections... 📚
Generating response... 🤖
3

Receive Answer

Get a comprehensive answer with code examples and source references
4

Follow-up Questions

Continue the conversation with contextual follow-up queries

Types of Questions That Work Best

✅ Excellent Question Types

How-To Questions

Examples:
  • “How do I set up authentication?”
  • “How to handle errors in the API?”
  • “How do I deploy this application?”

What-Is Questions

Examples:
  • “What is the UserService class?”
  • “What does the config.json file contain?”
  • “What are the available endpoints?”

Code Location Questions

Examples:
  • “Where is the database connection configured?”
  • “Where are the API routes defined?”
  • “Which file contains the main application logic?”

Best Practice Questions

Examples:
  • “What’s the recommended way to handle validation?”
  • “Best practices for error handling?”
  • “How should I structure my tests?”

❌ Less Effective Question Types

These types of questions may not yield optimal results:
  • Vague questions without context (“How does this work?”)
  • Questions about code not in your documentation
  • Highly specific implementation details not documented
  • Questions requiring real-time data or external information

Example Questions and Responses

API Documentation Questions

User: “How do I authenticate requests to the API?”

Code Structure Questions

User: “What’s the structure of the database models?”

Conversation History and Context

Context Retention

The Ask feature maintains conversation context throughout your session:
// Example conversation flow
const conversation = [
  {
    role: 'user',
    content: 'How do I set up the database?',
    timestamp: '2024-01-15T10:00:00Z'
  },
  {
    role: 'assistant', 
    content: 'To set up the database, you need to...',
    sources: ['/docs/setup.md', '/config/database.js'],
    timestamp: '2024-01-15T10:00:05Z'
  },
  {
    role: 'user',
    content: 'What about migrations?', // Context: Still about database setup
    timestamp: '2024-01-15T10:02:00Z'
  }
];

Follow-up Question Examples

Streaming Responses and Real-time Interaction

Streaming Implementation

The Ask feature provides real-time streaming responses for immediate feedback:
const askQuestion = async (question: string) => {
  const response = await fetch('/api/ask', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ question })
  });

  const reader = response.body?.getReader();
  const decoder = new TextDecoder();

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    
    const chunk = decoder.decode(value);
    const lines = chunk.split('\n');
    
    for (const line of lines) {
      if (line.startsWith('data: ')) {
        const data = JSON.parse(line.slice(6));
        updateUI(data); // Real-time UI updates
      }
    }
  }
};

Visual Feedback

Streaming Response Animation
The interface provides visual indicators for:
  • Search progress with animated loading states
  • Token-by-token streaming for real-time response building
  • Source highlighting as references are found
  • Completion status when the response is finished

API Usage for Programmatic Q&A

REST API Endpoints

curl -X POST "https://your-wiki.com/api/ask" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "question": "How do I implement user authentication?",
    "conversation_id": "conv_123",
    "include_sources": true,
    "stream": false
  }'

API Response Format

{
  "id": "ask_123456789",
  "question": "How do I authenticate users?",
  "answer": "To authenticate users in this API, you use JWT tokens...",
  "sources": [
    {
      "file": "/docs/authentication.md",
      "title": "Authentication Guide", 
      "relevance_score": 0.95,
      "excerpt": "JWT tokens are used for authentication..."
    },
    {
      "file": "/examples/auth.js",
      "title": "Authentication Example",
      "relevance_score": 0.87,
      "excerpt": "const token = jwt.sign(payload, secret);"
    }
  ],
  "conversation_id": "conv_123",
  "timestamp": "2024-01-15T10:30:00Z",
  "processing_time_ms": 1250
}

Best Practices for Effective Questions

🎯 Writing Better Questions

Be Specific

Instead of: “How does this work?”Try: “How does user authentication work in the login endpoint?”

Provide Context

Instead of: “Fix this error”Try: “How do I handle the ‘Database connection failed’ error when starting the server?”

Ask About Documented Features

Good: “What configuration options are available for the email service?”Less Good: “How do I integrate with an undocumented third-party service?”

Use Examples

Better: “How do I format a POST request to create a new user with email and password fields?”vs: “How do I create users?”

📝 Question Templates

How do I [specific action] in [specific context]?

Examples:
- How do I configure Redis caching in the production environment?
- How do I validate user input in the registration form?
- How do I set up database migrations for the User model?

💡 Advanced Query Techniques

Limitations and Troubleshooting

Known Limitations

Current limitations of the Ask feature:
  • Documentation Scope: Only searches indexed documentation and code files
  • Real-time Data: Cannot access live databases or external APIs
  • Code Execution: Cannot run or test code, only explain existing code
  • Version Specificity: May not distinguish between different versions of your code
  • Complex Logic: May struggle with highly complex business logic without clear documentation

Common Issues and Solutions

Performance Optimization Tips

Optimize your questions for better performance:
✅ Good Performance:
- Specific questions about documented features
- Questions referencing specific file names or classes
- Well-structured questions with clear context

❌ Poor Performance:  
- Extremely broad questions requiring full codebase analysis
- Questions about undocumented or external dependencies
- Vague questions without specific context

Debug Mode

Enable debug mode to troubleshoot issues:
const client = new DeepWikiClient({
  apiKey: 'your-api-key',
  debug: true  // Enables detailed logging
});

const response = await client.ask({
  question: "How does caching work?",
  debug: true  // Request debug information
});

console.log('Debug Info:', response.debug);
// Shows: query processing time, sources found, embedding similarity scores

Need Help?

Still having issues?
  • Check the API Documentation for detailed endpoint information
  • Review Common Patterns for question examples
  • Contact support with specific error messages and question examples
  • Join our community Discord for real-time help

Next Steps