Skip to content

Latest commit

 

History

History
178 lines (140 loc) · 3.34 KB

File metadata and controls

178 lines (140 loc) · 3.34 KB
title AI Integration Quick Start
description Quick guide to integrating AI features into ObjectStack applications

AI Integration Quick Start

Quick guide to integrating AI features into ObjectStack applications

Overview

ObjectStack provides built-in AI capabilities through the AI Protocol. This guide covers the essentials.

Agent Setup

1. Define an AI Agent

const agent = {
  name: 'sales_assistant',
  label: 'Sales Assistant',
  model: {
    provider: 'openai',
    modelName: 'gpt-4',
    temperature: 0.7,
  },
  tools: [
    'query_records',
    'create_record',
    'send_email',
  ],
  systemPrompt: 'You are a helpful sales assistant...',
};

2. Configure Model Registry

const modelRegistry = {
  models: [
    {
      id: 'gpt-4',
      provider: 'openai',
      capabilities: ['chat', 'function_calling'],
      limits: {
        maxTokens: 8192,
        maxContextLength: 128000,
      },
    },
  ],
};

RAG Pipeline

Basic RAG Configuration

const ragConfig = {
  knowledgeBases: ['product_docs', 'sales_playbook'],
  
  chunking: {
    strategy: 'semantic',
    chunkSize: 512,
    overlap: 50,
  },
  
  embedding: {
    model: 'text-embedding-ada-002',
    provider: 'openai',
  },
  
  vectorStore: {
    provider: 'pinecone',
    config: {
      apiKey: process.env.PINECONE_API_KEY,
      environment: 'production',
    },
  },
  
  retrieval: {
    topK: 5,
    minScore: 0.7,
  },
};

Natural Language Queries

Enable NLQ for Objects

const nlqConfig = {
  enabled: true,
  objects: ['customer_account', 'opportunity'],
  
  fieldMappings: [
    {
      synonyms: ['revenue', 'sales', 'income'],
      field: 'annual_revenue',
    },
    {
      synonyms: ['company', 'business', 'organization'],
      field: 'account_name',
    },
  ],
  
  examples: [
    {
      query: 'show me high value customers',
      intent: 'list',
      filters: [{ field: 'annual_revenue', operator: 'gt', value: 1000000 }],
    },
  ],
};

Using AI Tools

Query with Natural Language

const result = await ai.query({
  prompt: 'Show me all accounts in the technology industry with revenue over $1M',
  object: 'customer_account',
});

// Returns: QueryResult with structured data

Generate with AI

const generated = await ai.generate({
  prompt: 'Write a follow-up email for this customer',
  context: {
    customer: customerData,
    lastInteraction: interactionData,
  },
});

Best Practices

  1. Prompt Engineering

    • Be specific and clear
    • Provide context
    • Use examples
  2. Model Selection

    • Use appropriate model for task
    • Balance cost vs. capability
    • Consider latency requirements
  3. RAG Optimization

    • Chunk documents semantically
    • Use appropriate embedding models
    • Filter results by relevance score
  4. Error Handling

    • Handle model failures gracefully
    • Implement retry logic
    • Provide fallbacks

Examples

See the following example implementations:

For complete documentation, see AI_INTEGRATION_GUIDE.md


Last Updated: 2026-01-22