Embedding
Vectors are the retrieval side of RAG: every passage and every query becomes a float array, and similarity decides what the model sees. Embeddings::for() embeds many inputs in one call; the full reference (generation, multimodal inputs, caching) lives under Providers.
Widths for your columns
Size the vectors to the column that will hold them. dimensions() pins the width explicitly; without it the provider default applies:
use Crustum\Ai\Embeddings;
$response = Embeddings::for(['Napa Valley has great wine.'])->dimensions(1536)->generate();
echo count($response->first()) . " dimensions\n";2
3
4
5
1536 dimensionsPick the width once: the vector column length, the provider model, and every query must agree. Changing any of the three means re-embedding. Which providers embed, and their defaults, is a provider capability; local versus hosted is a cost and privacy call, not a code change.
Testing without keys
Fake the vector path and assert on the prompts the code built:
use Crustum\Ai\Embeddings;
use Crustum\Ai\Prompts\EmbeddingsPrompt;
Embeddings::fake();
$response = Embeddings::for([
'Napa Valley has great wine.',
'CakePHP is a PHP framework.',
])->dimensions(1536)->generate();
echo count($response->embeddings) . " embeddings\n";
Embeddings::assertGenerated(
fn (EmbeddingsPrompt $prompt) => $prompt->contains('CakePHP') && $prompt->dimensions === 1536,
);2
3
4
5
6
7
8
9
10
11
12
13
14
15
2 embeddingsassertGenerated() / assertNotGenerated() / assertNothingGenerated() cover the prompt; assertQueued() covers queued generations. Fakes return shape-correct vectors, so ranking code runs offline. For a byte-stable loop see RAG. Queued variants mirror the same assertions with QueuedEmbeddingsPrompt.
See also
- Providers — Embeddings — generation, multimodal, caching, similarity
- Loading — files in
- Stores — where vectors wait