Passionate software developer
IT-Entrepreneur, CoderDojo-Mentor, Teacher
software architects gmbh
rainer@software-architects.at
https://rainerstropek.me
https://bit.ly/oop-embeddings
100
100
Example: Personality Embeddings
See also: The Illustrated Word2vec
POST https://oai-4.openai.azure.com/openai/deployments/embeddings/
embeddings?api-version=2023-03-15-preview
api-key: {{$dotenv OAI_API_KEY}}
{
"input": "Here is the text for which you want to calculate the vector",
"model": "text-embedding-3-large"
}
Word/Phrase 1 | Word/Phrase 2 | Cosine Similarity |
---|---|---|
king | queen | 0.9154 |
king | König | 0.8854 |
king | frog | 0.8209 |
king | programming language | 0.7570 |
OpenAI
ChatGPT
End User
Model
Messages
(Chat History)
System, User, Assistant, Function
Functions
Options
OpenAI
Choices
Usage
POST https://oai-4.openai.azure.com/openai/deployments/
complete-4/chat/completions?api-version=2023-09-01-preview
api-key: {{$dotenv OAI_API_KEY}}
Content-Type: application/json
{
"messages": [
{
"role": "system",
"content": "You are a salesperson at a car dealer."
},
{
"role": "user",
"content": "Hi! I am unsure if I should buy a van or a sports car. What do you think?"
}
]
}
OpenAI
Application
End User
Question,
Query,
Command,
...
DB
Prompt
Azure.AI.OpenAI
Azure.Identity
Azure.Search.Documents
// Generate embeddings
async Task<float[]> GenerateEmbeddings(string text, OpenAIClient openAIClient)
{
var response = await openAIClient.GetEmbeddingsAsync(
new EmbeddingsOptions(embeddingsDeployment, [text]));
return response.Value.Data[0].Embedding.ToArray();
}
// Generate the embedding for the query
var queryEmbeddings = await GenerateEmbeddings(query, openAIClient);
// Perform the vector similarity search
var searchOptions = new SearchOptions
{
VectorSearch = new()
{
Queries =
{
new VectorizedQuery(queryEmbeddings)
{
Fields = { "contentVector" }, Exhaustive = true, KNearestNeighborsCount = 3
}
},
}
};
SearchResults<SearchDocument> response = await searchClient.SearchAsync<SearchDocument>(null, searchOptions);
Build prompt from results
Living with the Volkswagen ID.4
[...]
First impressions first
The ID.4 we’ve been testing was in the entry-level Life trim level but fitted with the bigger 77kWh
battery pack and the mid-level 204hp single electric motor of the Pro Performance drivetrain.
At £44,480 on the road – and £47,595 with options as tested – it’s towards the lower end of
what you can spend on one of these.
[...]
How difficult was it to keep charged?
[...] This in combination with the increasingly colder weather – no EV likes the cold – saw
the theoretical real-world range drop from around 260 miles when the ID.4 arrived to around 220 miles
after a few weeks of my custodianship. A far cry from the WLTP claim of 328 miles. [...]
[...]
What is the ID.4 like to live with then?
Day-to-day, it’s largely been brilliant. There is something undeniably conscience-easing
about pottering about the place in an electric vehicle, especially in Cambridge, among all
the cyclists and electric scooters. I do a lot of short urban journeys ferrying the kiddo
around, and not having to fire up a combustion engine – particularly on trips so short they
never even get through the warm-up phase – has been wonderful. But that, of course, is a
plus point you can apply to almost any EV.
[...]
How difficult was it to keep charged?
[...]
Journeys outside of this routine required a little more thinking ahead. Given I figured it
best to try and avoid stopping for 40 minutes to charge while travelling with the tiny terror,
this often meant making a dedicated trip to charge the car at Cambridge Services ahead of time.
[...]