Architecture Overview
AI plugin provides the fundamental building blocks for AI-powered features, including:
- Annotations for controlling embedding generation
- Text chunking for handling large content
- Text embedding generation for semantic search
Core Classes
AIRecordData
A modification class that adds AI specific data and behaviors to all Brightspot records.
- Automatically generates embeddings when records are saved
- Deletes embeddings when records are deleted
- Integrates with
VectorDatabasefor storage - Supports both new configuration (
@GenerateEmbedding) and legacy configuration (AskAIClient) - Handles text chunking before embedding generation
Whenever a record is saved, it follows these steps to generate an embedding:
- Checks if the record type should generate embeddings
- Chunks the content using
TextChunker - Generates embeddings for each chunk using
TextEmbeddingGenerator - Saves embeddings to the vector database
@GenerateEmbedding
A type-level annotation that marks a class for automatic embedding generation. For example, this is how to make sure that an embedding is generated each time an article is saved:
1@GenerateEmbedding2public class Article extends Content {3private String title;4private String body;5}
@ExcludeFromEmbedding
A field-level annotation that excludes specific fields from embedding generation. For example, this is how to exclude sensitive data from an embedding:
1@GenerateEmbedding2public class Article extends Content {3private String title;45@ExcludeFromEmbedding6private String internalId;7}
Common use cases are:
- Personally identifiable information (PII)
- Internal system identifiers
- Administrative metadata (creation dates, flags)
- Large binary data or encoded content
TextChunker
An abstract base class for splitting text into smaller chunks suitable for embedding generation. Typical use might look like:
1TextChunker chunker = TextChunker.get();2List<String> chunks = chunker.chunk("This is a very long piece of text that needs to be split...");
TextEmbeddingGenerator
An abstract base class for generating text embeddings (vector representations of text). Typical use might look like:
1TextEmbeddingGenerator generator = TextEmbeddingGenerator.get();2int tokens = generator.countTokens("This is some text");3float[] embedding = generator.generate("This is some text");
Typical Configuration
Configure the Text Chunker (optional)
1brightspot/ai/textChunker/class=com.brightspot.ai.chunker.FixedSizeTextChunker2brightspot/ai/textChunker/size=5123brightspot/ai/textChunker/overlap=0.1
Configure the Text Embedding Generator
1brightspot/ai/textEmbeddingGenerator/class=com.example.MyTextEmbeddingGenerator