The Kubiya Documentations service provides a powerful interface for querying the central knowledge base using the Trieve API.
It enables you to search documentation content with advanced semantic search capabilities, scoring, and flexible result formatting.
try: # Advanced search with custom parameters results = client.documentations.query( prompt="authentication setup guide", page_size=20, # Get more results search_type="bm25", # Use BM25 algorithm extend_results=True, # Include extended context score_threshold=0.5, # Lower threshold for more results render_markdown=False # Plain text formatting ) # Filter by content type code_results = [r for r in results if r['is_code']] doc_results = [r for r in results if not r['is_code']] print(f"Found {len(code_results)} code examples") print(f"Found {len(doc_results)} documentation sections") # Display code examples for result in code_results: print(f"\n📄 {result['title']}") print(f"Tags: {', '.join(result['tags'])}") print(f"```\n{result['raw_content']}\n```")except DocumentationError as e: print(f"Advanced search failed: {e}") if e.details: print(f"Error details: {e.details}")
# Good practice: Use natural language queriesresults = client.documentations.query( "How to set up authentication in Kubiya workflows")# Better than single keywords# results = client.documentations.query("auth")
results = client.documentations.query("search query")if not results: print("No results found. Try:") print("- Using broader search terms") print("- Checking spelling") print("- Using synonyms")else: print(f"Found {len(results)} results") for result in results[:5]: # Show top 5 print(f"• {result['title']}")
# Search for specific content typesresults = client.documentations.query( "Terraform configuration examples", page_size=50)# Filter by content characteristicstutorials = [r for r in results if 'tutorial' in r['title'].lower()]api_refs = [r for r in results if 'api' in r['group'].lower()]code_examples = [r for r in results if r['is_code']]print(f"Found {len(tutorials)} tutorials")print(f"Found {len(api_refs)} API references") print(f"Found {len(code_examples)} code examples")
def process_documentation_results(results): """Process and categorize search results""" categories = { 'guides': [], 'api_reference': [], 'examples': [], 'troubleshooting': [] } for result in results: title_lower = result['title'].lower() group_lower = result['group'].lower() if any(word in title_lower for word in ['guide', 'tutorial', 'getting started']): categories['guides'].append(result) elif any(word in group_lower for word in ['api', 'reference']): categories['api_reference'].append(result) elif result['is_code'] or 'example' in title_lower: categories['examples'].append(result) elif any(word in title_lower for word in ['troubleshoot', 'error', 'debug']): categories['troubleshooting'].append(result) return categories# Usageresults = client.documentations.query("Kubiya workflow development")categorized = process_documentation_results(results)for category, items in categorized.items(): if items: print(f"\n📋 {category.upper()} ({len(items)} items)") for item in items[:3]: # Show top 3 per category print(f" • {item['title']}")
# Use in workflow step for dynamic helpdef get_workflow_help(topic): try: results = client.documentations.query( f"Kubiya workflow {topic} guide", page_size=5, score_threshold=1.5 ) if results: help_text = f"# Help: {topic}\n\n" for result in results: help_text += f"## {result['title']}\n" help_text += f"{result['content']}\n\n" return help_text else: return f"No specific help found for '{topic}'" except DocumentationError: return "Help system temporarily unavailable"# Usage in workflowhelp_content = get_workflow_help("authentication")print(help_content)