ReadonlyEmbeddingReadonlyLocalGet the action vector service for semantic search. Initialized during Config - will be null before AIEngine.Config() completes.
Get the agent vector service for semantic search. Initialized during Config - will be null before AIEngine.Config() completes.
ProtectedBaseAccess to the underlying AIEngineBase instance
Returns the highest power local embedding model
Returns true if both the base engine and server capabilities are loaded
Returns an array of the local embedding models, sorted with the highest power models first
Returns the lowest power local embedding model
Optional metadata provider override. Callers should set
AIEngine.Instance.Provider = providerToUse before invoking entity-AI execution methods
in multi-provider contexts. Falls back to the global default provider when unset.
Get all available actions loaded from the database. Loaded during Config() - will be empty before AIEngine.Config() completes. NOTE: This returns MJActionEntity (MJ Action system), not the deprecated MJAIActionEntity. For deprecated AI Actions, see the inherited Actions property.
StaticInstanceUpdates the vector service to the latest vector contained within the specified agent example that is passed in
Updates the vector service to the latest vector containd within the specified agent note that is passed in
Wipes the entire agent base-catalog cache. Called on relevant entity changes and on reload.
Clears all cached text embeddings.
ProtectedcomposeCompose base scope filters (agentId/userId/companyId) with an optional additional filter into a single filter callback for use with FindNearest on examples.
Mirrors composeNoteFilters: Status filtering is NOT performed here. The vector store
is kept in sync with persisted Status by MJAIAgentExampleEntityServer.Save() /
Delete(), which call AddOrUpdateSingleExampleEmbedding / RemoveSingleExampleEmbedding
based on the example's current Status.
OptionalagentId: stringOptionaluserId: stringOptionalcompanyId: stringOptionaladditionalFilter: (metadata: ExampleEmbeddingMetadata) => booleanProtectedcomposeCompose base scope filters (agentId/userId/companyId) with an optional additional filter into a single filter callback for use with FindNearest.
Status filtering is NOT performed here. The invariant the retrieval path relies on is:
_noteVectorService contains an entry for a note iff its persisted Status is 'Active'.
That invariant is maintained write-side by MJAIAgentNoteEntityServer.Save(), which calls
AddOrUpdateSingleNoteEmbedding on Active saves and RemoveSingleNoteEmbedding on
non-Active saves. Deletes are handled by the same subclass's Delete() override.
This avoids a subtle bug the earlier Status-check-at-retrieval approach had: BaseAIEngine
overrides AdditionalLoading(), which disables BaseEngine's immediate-mutation path for
_agentNotes. Newly-created notes don't appear in this.AgentNotes until the next
Config(true) — so any retrieval-time lookup against that cache returned undefined for
post-startup notes and rejected everything.
OptionalagentId: stringOptionaluserId: stringOptionalcompanyId: stringOptionaladditionalFilter: (metadata: NoteEmbeddingMetadata) => booleanConfigures the AIEngine by first ensuring AIEngineBase is configured, then loading server-specific capabilities (embeddings, actions, etc.).
This method is safe to call from multiple places concurrently - it will return the same promise to all callers during loading.
OptionalforceRefresh: booleanIf true, forces a full reload even if already loaded
OptionalcontextUser: UserInfoUser context for server-side operations (required)
Optionalprovider: IMetadataProviderOptional metadata provider override
Generates a single embedding vector from multimodal content (text and/or interleaved image/audio/video/document blocks) using the given model's embedding provider.
This is the multimodal counterpart to EmbedText. Text-only content is routed through EmbedText so it reuses that method's caching, in-flight dedup, and empty-text guard. Actual media content takes the uncached provider path — multimodal payloads carry large base64 media that make a text-style cache key impractical and rarely repeat; providers that can't embed the media reject it.
the embedding model to use (provides DriverClass + APIName)
text, or interleaved text+media blocks, to embed into one fused vector
OptionalapiKey: stringoptional API key override
the embedding result, or null if the provider instance couldn't be created
Helper method to instantiate a class instance for the given model and calculate an embedding vector from the provided text.
Includes an LRU cache (see _embeddingCache) that dedupes concurrent calls for the same
(model, text) pair — the in-flight Promise is shared until it settles.
OptionalapiKey: stringOptionaloptions: { bypassCache?: boolean; noCache?: boolean }OptionalbypassCache?: booleanwhen true, skips the cache read but still populates it on success
OptionalnoCache?: booleanwhen true, neither reads nor writes the cache (also forfeits
promise dedup — a noCache caller always re-infers, even if
an equivalent inference is already in flight)
Empty/whitespace text short-circuits to null without invoking the embedding provider.
Helper method that generates an embedding for the given text using the highest power local embedding model.
Ensures AIEngine is fully loaded (both base metadata and server-specific capabilities like vector services) before the caller reads engine state. Idempotent: if already loaded, returns immediately. If a load is in flight (e.g. the deferred startup or another consumer triggered it), returns the same in-progress promise.
Mirrors BaseEngine.EnsureLoaded — added here because AIEngine extends
BaseSingleton (not BaseEngine) and has its own load orchestration to
cover server-specific setup (RefreshServerSpecificMetadata).
Use at any consumption point that touches AIEngine state, especially given AIEngineBase is registered as deferred at startup.
OptionalcontextUser: UserInfoOptionalprovider: IMetadataProviderFind actions similar to a task description using semantic search.
Find examples similar to query text using semantic search. Falls back to returning examples from cache if vector service is unavailable.
OptionalagentId: stringOptionaluserId: stringOptionalcompanyId: stringOptionaladditionalFilter: (metadata: ExampleEmbeddingMetadata) => booleanFind notes similar to query text using semantic search. Falls back to returning notes from cache if vector service is unavailable.
OptionalagentId: stringOptionaluserId: stringOptionalcompanyId: stringOptionaladditionalFilter: (metadata: NoteEmbeddingMetadata) => booleanFind agents similar to a task description using semantic search.
Returns the cached base catalog for an agent, or undefined if not yet built / invalidated.
The shape is defined and typed by the caller (BaseAgent) — pass the concrete type as T.
Optionalstatus: stringDouble-gated self-activation set — see AIEngineBase.GetAutoActivatableSkillsForAgent.
Optionaluser: UserInfoReturns the inheritance chain for a configuration, starting with the specified configuration and walking up through parent configurations to the root. Delegates to AIEngineBase.GetConfigurationChain.
The ID of the configuration to get the chain for
Array of MJAIConfigurationEntity objects representing the inheritance chain
Returns all configuration parameters for a configuration, including inherited parameters from parent configurations. Child parameters override parent parameters. Delegates to AIEngineBase.GetConfigurationParamsWithInheritance.
The ID of the configuration to get parameters for
Array of MJAIConfigurationParamEntity objects, with child overrides applied
ProtectedgetThe Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.
OptionalvendorName: stringOptionalcontextUser: UserInfoOptionalcontextUser: UserInfoOptionaluser: UserInfoProtectedGetOptionalstatus: "Active" | "Disabled" | "Pending"OptionalrelationshipStatus: "Active" | "Pending" | "Revoked"Executes the background startup sequence. This method is called automatically by the StartupManager. It runs AIEngine configuration and pre-warms the local embedding models and vector caches.
OptionalcontextUser: UserInfoThe authenticated user context (system/boot user context)
Optionalprovider: IMetadataProviderOptional metadata provider override
ProtectedmarkupProtectedpackageTakes in an example and packages up the metadata for the vector service
ProtectedpackageTakes in a note and packages up the metadata for the vector service
Executes multiple parallel chat completions with the same model but potentially different parameters.
The user's message/question to send to the model
The user context for authentication and logging
OptionalsystemPrompt: stringOptional system prompt to set the context/persona
Number of parallel completions to run (default: 3)
The amount to increment temperature for each iteration (default: 0.1)
The starting temperature value (default: 0.7)
Optionalmodel: MJAIModelEntityExtendedOptional specific model to use, otherwise uses highest power LLM
OptionalapiKey: stringOptional API key to use with the model
Optionalcallbacks: ParallelChatCompletionsCallbacksOptional callbacks for monitoring progress
Array of ChatResult objects, one for each parallel completion
Prepares standard chat parameters with system and user messages.
The user message/query to send to the model
OptionalsystemPrompt: stringOptional system prompt to set context/persona for the model
Array of properly formatted chat messages
Prepares an LLM model instance with the appropriate parameters. This method handles common tasks needed before calling an LLM:
The user context for authentication and permissions
Optionalmodel: MJAIModelEntityExtendedOptional specific model to use, otherwise uses highest power LLM
OptionalapiKey: stringOptional API key to use with the model
Object containing the prepared model instance and model information
Dynamically calculation of embeddings for all Active actions. Assumes that the internal Actions array is up to date, call
Loads Active actions from the base engine (contained within this class). Does not refresh from the database, simply
pulls the latest Active actions from the base class into its server side only array.
OptionalcontextUser: UserInfoRefreshes Agent embeddings - agents are pre-loaded at this point, but we need to generate, dynamically, embeddings from the text stored in the agent. This is not a cheap operation, use it sparingly.
Refresh the vector service with the latest persisted vectors that are stored in the Agent Examples table. This does not calculate embeddings, that is done by the AI Agent Example sub-class upon save as needed. This method simply uses the stored vectors and parses them from their JSON serialized format into vectors that are used by the vector service.
OptionalcontextUser: UserInfoRefresh the vector service with the latest persisted vectors that are stored in the Agent Notes table. This does not calculate embeddings, that is done by the AI Agent Note sub-class upon save as needed. This method simply uses the stored vectors and parses them from their JSON serialized format into vectors that are used by the vector service.
OptionalcontextUser: UserInfoRefreshes the server metadata including active actions. Refreshes the embeddings in the engine's vector service for
If you only need to refresh specific elements noted above, call the individual methods:
OptionalcontextUser: UserInfoForce regeneration of all embeddings for agents and actions.
Use this method when:
Note: This is an expensive operation and should not be called frequently. Normal auto-refresh operations will NOT regenerate embeddings to avoid performance issues.
OptionalcontextUser: UserInfoUser context for database operations (required on server-side)
Drops an example from the in-memory vector service. Called by the server-side entity subclass when an example is saved with a non-Active Status or is deleted, so subsequent FindSimilarAgentExamples calls cannot return it. Silently no-ops if the vector service isn't initialized yet (e.g., during early startup before Config has run).
Drops a note from the in-memory vector service. Called by the server-side entity subclass when a note is saved with a non-Active Status or is deleted, so subsequent FindSimilarAgentNotes calls cannot return it. Silently no-ops if the vector service isn't initialized yet (e.g., during early startup before Config has run).
Stores the base catalog for an agent (built once, reused across runs until invalidated).
Executes a simple completion task using the provided parameters.
The user message/query to send to the model
The user context for authentication and permissions
OptionalsystemPrompt: stringOptional system prompt to set context/persona for the model
Optionalmodel: MJAIModelEntityExtendedOptional specific model to use, otherwise uses highest power LLM
OptionalapiKey: stringOptional API key to use with the model
The text response from the LLM
Protected StaticgetReturns the singleton instance of the class. If the instance does not exist, it is created and stored in the Global Object Store. If className is provided it will be used as part of the key in the Global Object Store, otherwise the actual class name will be used. NOTE: the class name used by default is the lowest level of the object hierarchy, so if you have a class that extends another class, the lowest level class name will be used.
OptionalclassName: string
Server-side AI Engine that wraps AIEngineBase and adds server-only capabilities.
This class uses composition (containment) rather than inheritance to avoid duplicate data loading. It delegates all base functionality to AIEngineBase.Instance while adding server-specific features like embeddings, vector search, and LLM execution.
Description
ONLY USE ON SERVER-SIDE. For metadata only, use the AIEngineBase class which can be used anywhere.