Dify Knowledge Retrieval
Knowledge & Search
Dify Knowledge Retrieval
Dify External Knowledge API for searching CodeAlive repositories and workspaces
POST
Dify Knowledge Retrieval
Overview
This endpoint implements the Dify External Knowledge API specification, allowing Dify AI applications to query CodeAlive repositories and workspaces as knowledge bases. Use this endpoint to integrate CodeAlive’s code search capabilities into your Dify workflows and AI agents.Finding the knowledge_id
Theknowledge_id must be the ID of a repository or workspace from your CodeAlive account.
You can copy the ID from the CodeAlive UI:
- For repositories: Go to Repositories page, click the copy button next to the repository
- For workspaces: Go to Workspaces page, click the copy button next to the workspace
Request
The ID of the repository or workspace to search (e.g.,
"67f664fd4c2a00698a52bb6f")The search query describing what code or information you’re looking for
Settings for the retrieval operation
Optional metadata filtering conditions
Response
Array of search result records
Code Examples
Example Response
Filtering Examples
Filter by File Extension
Search only in C# files:Exclude Test Files
Search excluding test files:Multiple Conditions
Search for TypeScript files excluding tests:Error Responses
400 Bad Request (Error Code 1001)
Invalid request format or validation error:401 Unauthorized (Error Code 1004)
Authentication failed - invalid or missing API key:403 Forbidden (Error Code 1002)
Authorization failed - access denied to specified data source:404 Not Found (Error Code 1003)
Knowledge base not found:500 Internal Server Error (Error Code 2001)
Internal server error:Dify Integration
To use this endpoint in Dify:- In your Dify application, configure an External Knowledge Base
- Set the API endpoint to
https://app.codealive.ai/api/knowledge-retrieval/dify/retrieval - Add your CodeAlive API key in the
Authorizationheader asBearer YOUR_API_KEY - Use your repository or workspace ID as the
knowledge_id
Best Practices
Optimize Retrieval Quality
Optimize Retrieval Quality
- Set
score_thresholdto 0.7-0.8 for balanced results - Use
top_kbetween 3-10 for most use cases - Write specific, descriptive queries
- Include technical terms relevant to your search
Use Metadata Filtering
Use Metadata Filtering
- Filter by file extension to focus on specific languages
- Exclude test files for production code searches
- Use path filters to search specific directories
- Combine multiple conditions for precise results
Handle Results Effectively
Handle Results Effectively
- Check scores to gauge result relevance
- Use metadata for context about where code was found
- Leverage location info (line numbers) for precise references
- Process results in order of score (highest first)