Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 27 additions & 47 deletions examples/basic/ai-rag-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,14 @@
* - AI-powered question answering
*/

import type {
RAGPipelineConfig,
DocumentChunk,
DocumentMetadata,
RAGQueryRequest,
RAGQueryResponse,
Agent,
} from '@objectstack/spec';
import type { AI } from '@objectstack/spec';

/**
* Example 1: RAG Pipeline Configuration
*
* Complete RAG pipeline setup for a knowledge base system
*/
export const knowledgeBaseRAG: RAGPipelineConfig = {
export const knowledgeBaseRAG: AI.RAGPipelineConfig = {
name: 'knowledge_base_rag',
label: 'Knowledge Base RAG Pipeline',
description: 'RAG pipeline for company knowledge base',
Expand All @@ -43,6 +36,9 @@ export const knowledgeBaseRAG: RAGPipelineConfig = {
namespace: 'production',
dimensions: 1536,
metric: 'cosine',
batchSize: 100,
connectionPoolSize: 10,
timeout: 30000,
},

// Chunking strategy
Expand Down Expand Up @@ -76,14 +72,18 @@ export const knowledgeBaseRAG: RAGPipelineConfig = {
metadataFilters: {
status: 'published',
},

// Cache Configuration
enableCache: true,
cacheTTL: 3600,
};

/**
* Example 2: Document Ingestion
*
* How to index documents into the RAG pipeline
*/
export const sampleDocumentMetadata: DocumentMetadata[] = [
export const sampleDocumentMetadata: AI.DocumentMetadata[] = [
{
source: 'https://docs.objectstack.dev/architecture',
sourceType: 'url',
Expand All @@ -110,7 +110,7 @@ export const sampleDocumentMetadata: DocumentMetadata[] = [
},
];

export const sampleDocumentChunks: DocumentChunk[] = [
export const sampleDocumentChunks: AI.DocumentChunk[] = [
{
id: 'chunk_001',
content: `ObjectStack is a metadata-driven low-code platform that enables rapid application development.
Expand Down Expand Up @@ -145,12 +145,14 @@ Use the Agent protocol to define AI assistants with specific capabilities.`,
*
* Performing a RAG query with filters and options
*/
export const sampleQueries: RAGQueryRequest[] = [
export const sampleQueries: AI.RAGQueryRequest[] = [
{
// Simple question
query: 'What is ObjectStack?',
pipelineName: 'knowledge_base_rag',
topK: 5,
includeMetadata: true,
includeSources: true,
},
{
// Question with metadata filtering
Expand All @@ -160,6 +162,8 @@ export const sampleQueries: RAGQueryRequest[] = [
metadataFilters: {
category: 'Tutorial',
},
includeMetadata: true,
includeSources: true,
},
{
// Advanced query
Expand All @@ -179,7 +183,7 @@ export const sampleQueries: RAGQueryRequest[] = [
*
* What the pipeline returns
*/
export const sampleResults: RAGQueryResponse = {
export const sampleResults: AI.RAGQueryResponse = {
query: 'What is ObjectStack?',

// Retrieved chunks
Expand Down Expand Up @@ -214,33 +218,21 @@ It uses a three-layer architecture: ObjectQL for data, ObjectUI for presentation

[Source: https://docs.objectstack.dev/architecture]
The platform supports multiple databases and provides built-in AI capabilities.`,

// Metadata
processingTimeMs: 150,
totalResults: 2,
};

/**
* Example 5: AI Agent with RAG
*
* Integrating RAG into an AI agent
*/
export const ragEnabledAgent: Agent = {
export const ragEnabledAgent: AI.Agent = {
name: 'documentation_assistant',
type: 'conversational',
label: 'Documentation Assistant',
description: 'AI assistant powered by RAG for answering questions about ObjectStack',

// Agent capabilities
capabilities: {
objectAccess: [],
canCreate: false,
canUpdate: false,
canAnalyze: true,
},

role: 'Documentation Support Specialist',
active: true,

// System prompt with RAG instructions
systemPrompt: `You are a helpful documentation assistant for ObjectStack.
instructions: `You are a helpful documentation assistant for ObjectStack.

You have access to the knowledge base through RAG (Retrieval-Augmented Generation).
When answering questions:
Expand All @@ -252,18 +244,9 @@ When answering questions:
Always format your responses in a clear, structured way.`,

// RAG Configuration
rag: {
pipeline: 'knowledge_base_rag',
enabled: true,

// When to trigger RAG
trigger: 'always', // or 'auto', 'manual'

// Number of chunks to retrieve
topK: 5,

// Include source attribution
includeSources: true,
knowledge: {
indexes: ['knowledge-base'],
topics: ['ObjectStack', 'documentation'],
},

// Model configuration
Expand All @@ -277,12 +260,9 @@ Always format your responses in a clear, structured way.`,
// Tools (optional - for function calling)
tools: [
{
type: 'query',
name: 'search_documentation',
description: 'Search the ObjectStack documentation for specific topics',
parameters: {
query: 'string',
category: 'string?',
},
},
],
};
Expand All @@ -304,7 +284,7 @@ export function demonstrateRAGUsage() {
console.log('- Embedding query...');
console.log('- Searching vector database...');
console.log(`- Retrieved ${sampleResults.results.length} relevant chunks`);
console.log(`- Processing time: ${sampleResults.processingTimeMs}ms\n`);
console.log('- Processing complete\n');

// Step 3: Context is assembled
console.log('Assembled Context:');
Expand Down
17 changes: 7 additions & 10 deletions examples/basic/api-discovery-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
* Typically exposed at: GET /api/discovery
*/

import type {
DiscoveryResponse,
ApiCapabilities,
} from '@objectstack/spec';
import type { API } from '@objectstack/spec';

/**
* Example 1: Complete Discovery Response
*
* This is what a client receives when calling /api/discovery
*/
export const fullDiscoveryResponse: DiscoveryResponse = {
export const fullDiscoveryResponse: API.DiscoveryResponse = {
// System Identity
name: 'ObjectStack CRM',
version: '2.1.0',
Expand Down Expand Up @@ -57,7 +54,7 @@ export const fullDiscoveryResponse: DiscoveryResponse = {
*
* A simplified response for local development
*/
export const devDiscoveryResponse: DiscoveryResponse = {
export const devDiscoveryResponse: API.DiscoveryResponse = {
name: 'ObjectStack Dev',
version: '0.1.0',
environment: 'development',
Expand Down Expand Up @@ -88,12 +85,12 @@ export const devDiscoveryResponse: DiscoveryResponse = {
* How a client can use the discovery API to adapt its behavior
*/
export class AdaptiveClient {
private discovery: DiscoveryResponse | null = null;
private discovery: API.DiscoveryResponse | null = null;

async initialize(baseUrl: string) {
// Fetch discovery information
const response = await fetch(`${baseUrl}/api/discovery`);
this.discovery = await response.json() as DiscoveryResponse;
this.discovery = await response.json() as API.DiscoveryResponse;

console.log(`Connected to: ${this.discovery.name} v${this.discovery.version}`);
console.log(`Environment: ${this.discovery.environment}`);
Expand All @@ -102,7 +99,7 @@ export class AdaptiveClient {
/**
* Check if a specific feature is available
*/
hasFeature(feature: keyof ApiCapabilities): boolean {
hasFeature(feature: keyof API.ApiCapabilities): boolean {
if (!this.discovery) return false;
return this.discovery.features[feature] === true;
}
Expand Down Expand Up @@ -142,7 +139,7 @@ export class AdaptiveClient {
*
* How an AI agent can use discovery to understand the system
*/
export function generateSystemPromptFromDiscovery(discovery: DiscoveryResponse): string {
export function generateSystemPromptFromDiscovery(discovery: API.DiscoveryResponse): string {
const { name, version, features, locale } = discovery;

const prompt = `You are an AI assistant for ${name} (v${version}).
Expand Down
Loading
Loading