2.48.0 • Published 9 months ago

@memberjunction/ai-recommendations-rex v2.48.0

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

@memberjunction/ai-recommendations-rex

Overview

The @memberjunction/ai-recommendations-rex package provides a recommendation provider implementation for the MemberJunction framework that integrates with the rasa.io Rex recommendation engine. This provider enables AI-powered content recommendations based on vector similarity searches, delivering personalized content suggestions based on user preferences and behavior patterns.

Purpose and Functionality

This package implements the RecommendationProviderBase interface to:

  • Connect to the rasa.io Rex recommendation service via REST API
  • Generate personalized content recommendations using vector similarity searches
  • Process recommendation requests in configurable batch sizes
  • Convert Rex recommendations into MemberJunction recommendation entities
  • Handle error logging and reporting through the MemberJunction list system

Installation

npm install @memberjunction/ai-recommendations-rex

Configuration

The package requires the following environment variables:

# Rex API Configuration
REX_API_HOST=https://api.rex.rasa.io          # Rex API host URL
REX_RECOMMEND_HOST=https://recommend.rex.rasa.io  # Rex recommendation endpoint
REX_USERNAME=your_username                      # Rex account username
REX_PASSWORD=your_password                      # Rex account password
REX_API_KEY=your_api_key                       # Rex API key

# Optional Configuration
REX_BATCH_SIZE=200                             # Number of recommendations per batch (default: 200)

Usage

Important Note

This package is designed to be used through the MemberJunction Recommendation Engine and should not be instantiated directly in most cases.

Basic Example

import { RexRecommendationsProvider } from '@memberjunction/ai-recommendations-rex';
import { RecommendationRequest, RecommendationResult } from '@memberjunction/ai-recommendations';
import { UserInfo } from '@memberjunction/core';

// The provider is typically instantiated by the MJ framework
const provider = new RexRecommendationsProvider();

// Create a recommendation request
const request: RecommendationRequest<RecommendContextData> = {
    RunID: 'run-123',
    Recommendations: recommendationEntities, // Array of RecommendationEntity objects
    ErrorListID: 'error-list-id',
    CurrentUser: currentUser,
    Options: {
        EntityDocumentID: 'doc-123',
        TypeMap: {
            'course': 'Contents',
            'course_part': 'Course Parts',
            'person': 'Contributors'
        },
        type: 'article',
        filters: [
            { type: 'course', max_results: 10 }
        ]
    }
};

// Generate recommendations
const result: RecommendationResult = await provider.Recommend(request);

if (result.Success) {
    console.log('Recommendations generated successfully');
} else {
    console.error('Errors:', result.Errors);
    console.warn('Warnings:', result.Warnings);
}

API Documentation

Classes

RexRecommendationsProvider

The main provider class that implements the Rex recommendation integration.

Methods:

  • Recommend(request: RecommendationRequest<RecommendContextData>): Promise<RecommendationResult>
    • Processes recommendation requests by communicating with the Rex API
    • Handles batch processing based on configured batch size
    • Returns a RecommendationResult with success status and any errors/warnings

Type Definitions

RecommendContextData

type RecommendContextData = {
    EntityDocumentID: string;          // Required: ID of the entity document
    TypeMap: Record<string, string>;   // Mapping of Rex types to MJ entity names
    type: string;                      // Content type for recommendations
    filters: {                         // Filtering options for recommendations
        type: string;
        max_results: number;
    }[];
};

RecommendationResponse

type RecommendationResponse = {
    engine: string;      // Rex engine identifier
    version: string;     // API version
    id: string;         // Recommendation ID
    model: string;      // Model used for recommendation
    score: number;      // Similarity score (0-1)
    source: string;     // Data source
    type: string;       // Content type
    vector_id: string;  // Vector database ID
};

Prerequisites

  1. rasa.io Rex Account: Valid Rex credentials and API key
  2. MemberJunction Framework: Properly configured MJ installation
  3. Vector Database: Configured vector storage with indexed content
  4. Entity Record Documents: Source records must have associated vector embeddings

Integration with MemberJunction

This provider integrates with several MemberJunction packages:

  • @memberjunction/ai-recommendations: Base recommendation framework
  • @memberjunction/core: Core MJ functionality and entities
  • @memberjunction/core-entities: Entity definitions for recommendations
  • @memberjunction/global: Global utilities and class registration

Workflow

  1. The MJ Recommendation Engine creates recommendation requests
  2. Rex provider fetches entity record documents with vector IDs
  3. Rex API performs similarity searches in the vector database
  4. Results are converted to MemberJunction recommendation items
  5. Recommendations are saved to the database for retrieval

Error Handling

The provider implements comprehensive error handling:

  • API errors are logged with full details
  • Failed recommendations are recorded in the specified error list
  • Batch processing continues even if individual recommendations fail
  • All errors and warnings are aggregated in the result object

Performance Considerations

  • Batch Processing: Recommendations are processed in configurable batches (default: 200)
  • Parallel Processing: Each batch processes recommendations in parallel
  • Token Management: Access tokens are obtained and managed automatically
  • Score Clamping: Probability scores are normalized to 0-1 range

Build and Development

# Build the package
npm run build

# Run in development mode
npm start

# Run tests (when available)
npm test

Dependencies

  • axios: HTTP client for Rex API communication
  • openai: OpenAI SDK (for potential future enhancements)
  • dotenv: Environment variable management
  • @memberjunction/ai: Core AI functionality
  • @memberjunction/ai-recommendations: Recommendation framework
  • @memberjunction/global: MJ global utilities

License

ISC License - See LICENSE file for details

Support

For issues and questions:

Version

Current version: 2.43.0

2.27.1

1 year ago

2.23.2

1 year ago

2.46.0

9 months ago

2.23.1

1 year ago

2.27.0

1 year ago

2.34.0

11 months ago

2.30.0

12 months ago

2.19.4

1 year ago

2.19.5

1 year ago

2.19.2

1 year ago

2.19.3

1 year ago

2.19.0

1 year ago

2.19.1

1 year ago

2.15.2

1 year ago

2.34.2

11 months ago

2.15.0

1 year ago

2.34.1

11 months ago

2.38.0

10 months ago

2.45.0

9 months ago

2.22.1

1 year ago

2.22.0

1 year ago

2.41.0

10 months ago

2.22.2

1 year ago

2.26.1

1 year ago

2.26.0

1 year ago

2.33.0

11 months ago

2.18.3

1 year ago

2.18.1

1 year ago

2.18.2

1 year ago

2.18.0

1 year ago

2.37.1

10 months ago

2.37.0

10 months ago

2.14.0

1 year ago

2.21.0

1 year ago

2.44.0

10 months ago

2.40.0

10 months ago

2.29.0

1 year ago

2.29.2

1 year ago

2.29.1

1 year ago

2.25.0

1 year ago

2.48.0

9 months ago

2.32.0

12 months ago

2.32.2

12 months ago

2.32.1

12 months ago

2.17.0

1 year ago

2.13.4

1 year ago

2.36.0

11 months ago

2.13.2

1 year ago

2.13.3

1 year ago

2.13.0

1 year ago

2.36.1

11 months ago

2.13.1

1 year ago

2.43.0

10 months ago

2.20.2

1 year ago

2.20.3

1 year ago

2.20.0

1 year ago

2.20.1

1 year ago

2.28.0

1 year ago

2.47.0

9 months ago

2.24.1

1 year ago

2.24.0

1 year ago

2.31.0

12 months ago

2.12.0

1 year ago

2.39.0

10 months ago

2.16.1

1 year ago

2.35.1

11 months ago

2.35.0

11 months ago

2.16.0

1 year ago

2.42.1

10 months ago

2.42.0

10 months ago

2.23.0

1 year ago

2.11.0

1 year ago

2.10.0

1 year ago

2.9.0

1 year ago

2.8.0

1 year ago

2.7.0

1 year ago

2.6.1

1 year ago

2.5.2

1 year ago

2.6.0

1 year ago

2.7.1

1 year ago

2.5.1

1 year ago

2.5.0

1 year ago

2.4.1

2 years ago

2.4.0

2 years ago

2.3.3

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.3.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.5

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.0.0

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.3

2 years ago