Searches.do - Elegant Contextual Data Retrieval
Seamless access to contextual data through elegant, type-safe searches
Overview
Searches.do is a core primitive of the .do ecosystem, providing a clean, type-safe interface for retrieving contextual data from various sources. This SDK enables functions, workflows, and agents to access relevant information when needed, enhancing decision-making capabilities across your business processes.
The Challenge
Contextual data retrieval presents several challenges:
- Data Source Diversity: Accessing information across disparate systems
- Query Complexity: Formulating precise queries for relevant results
- Context Awareness: Understanding the context of search requests
- Result Relevance: Delivering the most valuable information first
- Performance: Retrieving data quickly without compromising quality
The Solution
Searches.do provides an elegant, type-safe interface for contextual data retrieval:
- Unified Data Access: Consistent patterns for accessing any data source
- Intelligent Queries: Simple yet powerful query capabilities
- Context-Aware Results: Results tailored to the specific use case
- Relevance Optimization: Most valuable information prioritized
- Seamless Performance: Fast retrieval without compromising quality
Key Features
- Elegant API Design - Clean, intuitive interfaces for data retrieval
- Type-Safe Queries - Strongly-typed queries and results for reliable integration
- Multi-Source Access - Unified interface for diverse data sources
- Context-Aware Results - Results tailored to the specific use case
- Seamless Integration - Works with all .do services
- Minimal Configuration - Simple setup with sensible defaults
Elegant API Design
Searches.do provides a clean, intuitive interface for contextual data retrieval:
import { Searches } from 'searches.do'
// Simple initialization with default settings
const searches = new Searches()
// Or with custom configuration
const searches = new Searches({
apiKey: process.env.SEARCHES_API_KEY,
baseUrl: process.env.SEARCHES_API_URL || 'https://searches.do',
})
Performing Searches
// Simple search with minimal configuration
const results = await searches.search('customers', {
query: 'enterprise clients in healthcare',
limit: 10,
})
// Advanced search with type-safe filters
const filteredResults = await searches.search('products', {
query: 'wireless headphones',
filters: {
price: { range: [100, 300] },
brand: { in: ['Sony', 'Bose', 'Apple'] },
inStock: true,
},
sort: { field: 'rating', order: 'desc' },
limit: 20,
})
// Access strongly-typed results
console.log(`Found ${results.total} results`)
results.items.forEach((item) => {
console.log(`${item.name}: ${item.description}`)
})
Managing Search Sources
// List available search sources
const sources = await searches.listSources()
// Get details about a specific search source
const customerSource = await searches.getSource('customers')
console.log(customerSource.schema) // View source schema
Integration with the .do Ecosystem
Searches.do is designed to work seamlessly with other .do services:
import { AI } from 'functions.do'
import { Workflow } from 'workflows.do'
import { Searches } from 'searches.do'
// Initialize services
const searches = new Searches()
// Define AI functions that use searches
const ai = AI({
recommendProducts: async ({ customerQuery, preferences }) => {
// Use searches.do to find relevant products
const products = await searches.search('products', {
query: customerQuery,
filters: {
category: { in: preferences.categories },
price: { range: [preferences.minPrice, preferences.maxPrice] },
},
limit: 5,
})
// Process and return recommendations
return {
recommendations: products.items.map((product) => ({
id: product.id,
name: product.name,
price: product.price,
rating: product.rating,
imageUrl: product.imageUrl,
})),
totalMatches: products.total,
}
},
})
// Define a workflow that uses both functions and searches
const workflow = new Workflow({
name: 'Customer Support',
steps: [
{
name: 'Find Similar Issues',
search: 'knowledgeBase',
input: {
query: '{{trigger.customerQuery}}',
filters: {
category: 'technical-support',
product: '{{trigger.productId}}',
},
},
},
{
name: 'Generate Response',
function: 'createSupportResponse',
input: {
customerQuery: '{{trigger.customerQuery}}',
similarIssues: '{{steps.findSimilarIssues.items}}',
customerName: '{{trigger.customerName}}',
},
},
],
})
Installation
npm install searches.do
# or
yarn add searches.do
# or
pnpm add searches.do
The .do Ecosystem
Searches.do is a core primitive of the .do ecosystem, designed to work seamlessly with other .do services:
- apis.do - The foundational SDK and unified API Gateway
- functions.do - Strongly-typed AI functions
- workflows.do - Business process orchestration
- agents.do - Autonomous digital workers
- actions.do - External system operations
- triggers.do - Event-driven process initiation