|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIU. - OpenAI API > !Core Operations > AIU. - Artificial Intelligence Utility |
MiniRobotLanguage (MRL)
AIU.Embed
Generate Embeddings
Intention
Embed Command: Converting Text to Numerical Representations
The Embed command generates embeddings—numerical vectors representing text—using OpenAI’s embeddings API.
This is useful for tasks like semantic search, text classification, or clustering within your automation scripts.
It’s part of the AIU - OpenAI API suite.
The Embed command sends a text input to an OpenAI embeddings model (e.g., text-embedding-3-large) via the AIU.SetEmbeddingsEndpoint and returns a JSON-formatted array of numerical embeddings.
You can store the result in a variable or copy it to the clipboard for further processing.
Generating embeddings is essential for:
•Semantic Analysis: Compare text similarity for search or recommendation systems.
•Machine Learning: Use embeddings as input features for models.
•Data Processing: Transform text into a format suitable for mathematical operations.
Provide a text input string, an optional return variable, and an optional clipboard flag (0 or 1). The embeddings are returned as a JSON string containing an array of floating-point numbers.
Available embedding models and their prices (as of March 18, 2025, from OpenAI’s pricing page) include:
•text-embedding-3-large: $0.13/1M tokens (3072 dimensions).
•text-embedding-3-small: $0.02/1M tokens (1536 dimensions).
•text-embedding-ada-002: $0.10/1M tokens (1536 dimensions, legacy).
Example Usage
AIU.SetModel|text-embedding-3-small
AIU.Embed|Hello world|$$EMB|1
DBP.Embeddings: $$EMB
This generates embeddings for 'Hello world', stores them in $$EMB, and copies them to the clipboard.
Illustration
┌──────────────────────────────┐
│ Input Text │
├──────────────────────────────┤
│ Hello world │
├──────┬───────────────────────┤
│ Emb │ [0.12, -0.34, ...] │
└──────┴───────────────────────┘
Text transformed into a numerical vector.
Syntax
AIU.Embed|P1[|P2[|P3]]
AIU.Embed|$$INPUT[|$$RET[|CLIP]]
Parameter Explanation
P1 ($$INPUT) - The text input to generate embeddings for (required).
P2 ($$RET) - (Optional) The variable to store the embeddings JSON string. If omitted, the result is not stored in a variable.
P3 (CLIP) - (Optional) A flag (0 or 1) to copy the embeddings to the clipboard (1 = yes, 0 = no, default is 0).
Example
AIU.SetModel|text-embedding-3-large
AIU.Embed|What is AI?|$$VEC|0
DBP.Embedding Vector: $$VEC
ENR.
Remarks
- Requires a valid API key set via AIU.Set_Key.
- The output is a JSON string, typically an array of floats (e.g., [0.12, -0.34, ...]), with length depending on the model (e.g., 3072 for text-embedding-3-large).
Limitations
- Input text length is limited to 8192 tokens for most OpenAI embedding models as of March 18, 2025.
- Requires an active internet connection and valid API credentials.
See also: