Context Search Skill
This skill provides two main capabilities for interacting with context-aware knowledge bases:
- Search: Retrieve relevant documents based on text queries
- Chat: Have conversations with RAG-powered systems
Configuration
This skill requires:
- Environment Variable: Set the
CTX_SEARCH_API_KEYenvironment variable with your API key:export CTX_SEARCH_API_KEY='your-api-key-here' - Config File: Create a
config.jsonfile in the skill directory with the following structure:
{
"contexts": {
"default": {
"type": "",
"base_url": "https://your-api-endpoint.com",
"description": "Default context service"
},
"knowledge-base-a": {
"type": "",
"base_url": "https://another-endpoint.com",
"description": "Knowledge base A for technical docs"
}
}
}Context Type: Each context can optionally define a type:
- (empty / missing): Knowledge base (default; supports
searchandchat) image: Image context (supportssearchonly)video: Video context (supportssearchonly)
Multiple Knowledge Base Support: You can configure multiple knowledge bases for different scenarios in the config.json file. Each knowledge base is identified by a unique name (e.g., "default", "knowledge-base-a") and can have its own base_url and description. This allows you to:
- Separate knowledge bases by topic or domain (e.g., technical docs, product manuals, FAQs)
- Use different knowledge bases for different projects or teams
- Switch between knowledge bases using the
--contextparameter
Example configuration for multiple scenarios:
{
"contexts": {
"tech-docs": {
"type": "",
"base_url": "https://tech-docs.example.com",
"description": "Technical documentation and API references"
},
"product-manuals": {
"type": "",
"base_url": "https://manuals.example.com",
"description": "Product user manuals and guides"
},
"internal-wiki": {
"type": "",
"base_url": "https://wiki.example.com",
"description": "Internal company knowledge base"
},
"image-index": {
"type": "image",
"base_url": "https://image.example.com",
"description": "Image search context (search only)"
}
}
}Usage
Running the Script
Important: The script must be run from the skill directory (where config.json is located).
cd <skill-directory>
uv run scripts/context_search.py <command> [args...] \
|| python3 scripts/context_search.py <command> [args...] \
|| python scripts/context_search.py <command> [args...]List Available Knowledge Bases
List all configured knowledge bases:
uv run scripts/context_search.py listParameters:
--json: Output raw JSON response (optional)
Example:
uv run scripts/context_search.py listThis will display all available knowledge bases with their descriptions and base URLs.
Search Function
Use the search function to retrieve relevant documents:
uv run scripts/context_search.py search \
--context <context-name> \
--text "your search query" \
--mode <quick|normal|deep> \
--size <number-of-results>Parameters:
--context: Name of the context service (default: "default")--text: The search query text--mode: Search mode -quick,normal, ordeep(default: not sent, uses server default). Note: For image and video contexts, onlyquickmode is supported; if not specified, defaults toquick.--size: Number of results to return (default: not sent, uses server default)
Example:
uv run scripts/context_search.py search \
--context knowledge-base-a \
--text "how to implement authentication" \
--mode deep \
--size 10Chat Function
Use the chat function to have conversations with the RAG system:
uv run scripts/context_search.py chat \
--context <context-name> \
--message "your message" \
--mode <quick|normal|deep> \
--size <number-of-results> \
--streamParameters:
--context: Name of the context service (default: "default")--message: The message to send--mode: Chat mode -quick,normal, ordeep(default: not sent, uses server default)--size: Number of results to return (default: 5)--stream: Enable streaming output (optional flag)
Note: chat is only supported for knowledge base contexts (type is empty/missing). For type: "image" or type: "video", use search.
Example:
uv run scripts/context_search.py chat \
--context default \
--message "What are the best practices for API design?" \
--mode deep \
--size 10Mode Descriptions
- quick: Fast response, suitable for simple queries
- normal: Balanced speed and quality (default)
- deep: Comprehensive search/chat, best for complex queries
Output Format
Search Output
Returns a JSON object with search results:
- Document ID
- Content
- Relevance score
- Metadata including retrieval score and index
Chat Output
Returns a JSON object with:
- Response content
- Token usage statistics
- Model information
Error Handling
The script will display error messages if:
CTX_SEARCH_API_KEYenvironment variable is not set- Configuration file is missing or invalid
- Network connection fails
- Invalid context name is provided
Setting Up Configuration
- Set the environment variable:
export CTX_SEARCH_API_KEY='your-api-key-here' - Copy the
config.json.templatefile toconfig.json - Fill in the base URLs for each context service
- Add as many context services as needed
- Keep the config file secure and never commit it to version control