environment-setup-guide
Guide developers through setting up development environments with proper tools, dependencies, and configurations
openevidence-performance-tuning
Optimize OpenEvidence clinical query performance and response times. Use when improving latency, optimizing query efficiency, or tuning caching for clinical AI applications. Trigger with phrases like "openevidence performance", "openevidence slow", "optimize openevidence", "openevidence latency",...
Full skill instructions
Optimize OpenEvidence clinical query performance for point-of-care response times.
openevidence-observability)| Metric | Target | Critical |
|---|---|---|
| Clinical Query P50 | < 3s | > 10s |
| Clinical Query P95 | < 8s | > 15s |
| Clinical Query P99 | < 15s | > 30s |
| DeepConsult Start | < 5s | > 15s |
| Cache Hit Rate | > 70% | < 50% |
// src/services/optimized-query.ts
// 1. Optimize question structure
function optimizeQuestion(question: string): string {
// Remove unnecessary words
let optimized = question
.replace(/\b(please|can you|could you|I want to know)\b/gi, '')
.replace(/\s+/g, ' ')
.trim();
// Ensure question ends with ?
if (!optimized.endsWith('?')) {
optimized += '?';
}
return optimized;
}
// 2. Optimize context to reduce processing
function optimizeContext(context: ClinicalContext): ClinicalContext {
return {
specialty: context.specialty,
urgency: context.urgency,
// Only include relevant patient context
...(context.patientAge && { patientAge: context.patientAge }),
...(context.patientSex && { patientSex: context.patientSex }),
// Limit conditions to top 5 most relevant
...(context.relevantConditions && {
relevantConditions: context.relevantConditions.slice(0, 5),
}),
// Limit medications to top 10
...(context.currentMedications && {
currentMedications: context.currentMedications.slice(0, 10),
}),
};
}
// 3. Optimize query options
const OPTIMIZED_OPTIONS = {
maxCitations: 5, // More citations = slower response
includeGuidelines: true, // High value, low overhead
includeDrugInfo: false, // Only when needed
prioritizeRecent: true, // Faster index access
};
// src/cache/clinical-cache.ts
import { createHash } from 'crypto';
import Redis from 'ioredis';
interface CacheConfig {
redis: Redis;
defaultTTL: number;
maxEntries: number;
}
interface CachedResponse {
data: any;
cachedAt: number;
ttl: number;
hitCount: number;
}
export class ClinicalQueryCache {
private redis: Redis;
private defaultTTL: number;
private prefix = 'oe:query:';
constructor(config: CacheConfig) {
this.redis = config.redis;
this.defaultTTL = config.defaultTTL;
}
// Generate cache key from query
private generateKey(question: string, context: ClinicalContext): string {
const normalized = JSON.stringify({
q: question.toLowerCase().trim(),
s: context.specialty,
u: context.urgency,
});
return this.prefix + createHash('sha256').update(normalized).digest('hex').substring(0, 16);
}
// Determine TTL based on query type
private getTTL(question: string, context: ClinicalContext): number {
const lowerQuestion = question.toLowerCase();
// Short TTL for time-sensitive queries
if (context.urgency === 'stat' || context.urgency === 'urgent') {
return 300; // 5 minutes
}
// Longer TTL for stable medical facts
if (lowerQuestion.includes('mechanism') ||
lowerQuestion.includes('pharmacokinetics') ||
lowerQuestion.includes('half-life')) {
return 86400; // 24 hours
}
// Medium TTL for treatment guidelines (may update)
if (lowerQuestion.includes('guideline') ||
lowerQuestion.includes('first-line') ||
lowerQuestion.includes('recommended')) {
return 3600; // 1 hour
}
return this.defaultTTL;
}
async get(question: string, context: ClinicalContext): Promise<any | null> {
const key = this.generateKey(question, context);
const cached = await this.redis.get(key);
if (!cached) return null;
const entry: CachedResponse = JSON.parse(cached);
// Increment hit count
entry.hitCount++;
await this.redis.setex(key, entry.ttl, JSON.stringify(entry));
return entry.data;
}
async set(
question: string,
context: ClinicalContext,
data: any
): Promise<void> {
const key = this.generateKey(question, context);
const ttl = this.getTTL(question, context);
const entry: CachedResponse = {
data,
cachedAt: Date.now(),
ttl,
hitCount: 0,
};
await this.redis.setex(key, ttl, JSON.stringify(entry));
}
async invalidate(pattern?: string): Promise<number> {
const keys = await this.redis.keys(this.prefix + (pattern || '*'));
if (keys.length === 0) return 0;
return this.redis.del(...keys);
}
async getStats(): Promise<{
totalKeys: number;
memoryUsage: string;
hitRate: number;
}> {
const keys = await this.redis.keys(this.prefix + '*');
const info = await this.redis.info('memory');
let totalHits = 0;
let totalEntries = 0;
for (const key of keys.slice(0, 100)) {
const cached = await this.redis.get(key);
if (cached) {
const entry: CachedResponse = JSON.parse(cached);
totalHits += entry.hitCount;
totalEntries++;
}
}
return {
totalKeys: keys.length,
memoryUsage: info.match(/used_memory_human:(\S+)/)?.[1] || 'unknown',
hitRate: totalEntries > 0 ? totalHits / totalEntries : 0,
};
}
}
// src/openevidence/optimized-client.ts
import { OpenEvidenceClient } from '@openevidence/sdk';
import { Agent } from 'https';
// Reuse connections with keep-alive
const httpsAgent = new Agent({
keepAlive: true,
keepAliveMsecs: 30000,
maxSockets: 10,
maxFreeSockets: 5,
});
export const optimizedClient = new OpenEvidenceClient({
apiKey: process.env.OPENEVIDENCE_API_KEY!,
orgId: process.env.OPENEVIDENCE_ORG_ID!,
httpAgent: httpsAgent,
timeout: 30000,
});
// Pre-warm connections on startup
export async function warmupConnections(): Promise<void> {
console.log('[Performance] Warming up OpenEvidence connections...');
try {
// Make a lightweight request to establish connection
await optimizedClient.health.check();
console.log('[Performance] Connection pool warmed up');
} catch (error) {
console.error('[Performance] Warmup failed:', error);
}
}
// src/services/batch-query.ts
import DataLoader from 'dataloader';
// Batch multiple clinical queries
const queryBatcher = new DataLoader<
{ question: string; context: ClinicalContext },
ClinicalQueryResponse
>(
async (queries) => {
// OpenEvidence may support batch API in future
// For now, parallelize within rate limits
const results = await Promise.all(
queries.map(q => optimizedClient.query({
question: q.question,
context: q.context,
}))
);
return results;
},
{
maxBatchSize: 5, // Respect rate limits
batchScheduleFn: (callback) => setTimeout(callback, 50), // 50ms window
cacheKeyFn: (query) => `${query.question}:${query.context.specialty}`,
}
);
// Usage in service
export async function batchedQuery(
question: string,
context: ClinicalContext
): Promise<ClinicalQueryResponse> {
return queryBatcher.load({ question, context });
}
// src/services/streaming-query.ts
// Use streaming for faster perceived performance
export async function streamingClinicalQuery(
question: string,
context: ClinicalContext,
onPartialResponse: (partial: string) => void
): Promise<ClinicalQueryResponse> {
// Check if streaming is supported
if (optimizedClient.supportsStreaming?.()) {
const stream = await optimizedClient.query.stream({
question,
context,
});
let fullAnswer = '';
for await (const chunk of stream) {
fullAnswer += chunk.text;
onPartialResponse(fullAnswer);
}
return stream.finalResponse;
}
// Fallback to regular query
const response = await optimizedClient.query({ question, context });
onPartialResponse(response.answer);
return response;
}
// src/monitoring/performance-metrics.ts
import { Histogram, Counter, Gauge } from 'prom-client';
// Latency histogram
const queryLatency = new Histogram({
name: 'openevidence_query_duration_seconds',
help: 'Clinical query latency',
labelNames: ['specialty', 'urgency', 'cached'],
buckets: [0.5, 1, 2, 5, 10, 15, 30],
});
// Cache metrics
const cacheHits = new Counter({
name: 'openevidence_cache_hits_total',
help: 'Cache hit count',
});
const cacheMisses = new Counter({
name: 'openevidence_cache_misses_total',
help: 'Cache miss count',
});
// Current queue size
const queueSize = new Gauge({
name: 'openevidence_queue_size',
help: 'Current request queue size',
labelNames: ['priority'],
});
// Instrumented query function
export async function instrumentedQuery(
question: string,
context: ClinicalContext,
cache: ClinicalQueryCache
): Promise<ClinicalQueryResponse> {
const timer = queryLatency.startTimer({
specialty: context.specialty,
urgency: context.urgency,
});
// Check cache first
const cached = await cache.get(question, context);
if (cached) {
cacheHits.inc();
timer({ cached: 'true' });
return cached;
}
cacheMisses.inc();
// Query API
const response = await optimizedClient.query({ question, context });
// Cache response
await cache.set(question, context, response);
timer({ cached: 'false' });
return response;
}
| Performance Issue | Detection | Resolution |
|---|---|---|
| High P95 latency | Metrics alert | Check cache hit rate, optimize queries |
| Low cache hit rate | < 50% hits | Review TTL strategy, increase cache size |
| Connection timeouts | Timeout errors | Check keep-alive, increase pool size |
| Memory pressure | Redis alerts | Implement LRU eviction |
For cost optimization, see openevidence-cost-tuning.
Guide developers through setting up development environments with proper tools, dependencies, and configurations
Implement Exa lint rules, policy enforcement, and automated guardrails. Use when setting up code quality rules for Exa integrations, implementing pre-commit hooks, or configuring CI policy checks for Exa best practices. Trigger with phrases like "exa policy", "exa lint", "exa guardrails", "exa be...
Configure CI/CD pipelines for Documenso integrations. Use when setting up automated testing, deployment pipelines, or continuous integration for Documenso projects. Trigger with phrases like "documenso CI", "documenso GitHub Actions", "documenso pipeline", "documenso automated testing".
Build check model availability and implement fallback chains. Use when building resilient systems or handling model outages. Trigger with phrases like 'openrouter availability', 'openrouter fallback', 'openrouter model down', 'openrouter health check'.
Configure Langfuse enterprise organization management and access control. Use when implementing team access controls, configuring organization settings, or setting up role-based permissions for Langfuse projects. Trigger with phrases like "langfuse RBAC", "langfuse teams", "langfuse organization"...
Execute compliance and security auditing for Cursor usage. Triggers on "cursor compliance", "cursor audit", "cursor security review", "cursor soc2", "cursor gdpr". Use when analyzing or auditing cursor compliance audit. Trigger with phrases like "cursor compliance audit", "cursor audit", "cursor".
Configure Apollo.io CI/CD integration. Use when setting up automated testing, continuous integration, or deployment pipelines for Apollo integrations. Trigger with phrases like "apollo ci", "apollo github actions", "apollo pipeline", "apollo ci/cd", "apollo automated tests".
Create robust Python automation with full logging and safety checks. Use when tasks need complex data processing, authenticated API work, conditional file operations, or error handling beyond simple shell commands.
Configure PostHog across development, staging, and production environments. Use when setting up multi-environment deployments, configuring per-environment secrets, or implementing environment-specific PostHog configurations. Trigger with phrases like "posthog environments", "posthog staging", "po...
Expert in designing and building autonomous AI agents. Masters tool use, memory systems, planning strategies, and multi-agent orchestration. Use when: build agent, AI agent, autonomous agent, tool use, function calling.
Validate insecure deserialization checker operations. Auto-activating skill for Security Fundamentals. Triggers on: insecure deserialization checker, insecure deserialization checker Part of the Security Fundamentals skill category. Use when working with insecure deserialization checker functiona...
Manage path traversal finder operations. Auto-activating skill for Security Fundamentals. Triggers on: path traversal finder, path traversal finder Part of the Security Fundamentals skill category. Use when working with path traversal finder functionality. Trigger with phrases like "path traversa...
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience