Last week on Dec 7, I had an opportunity to speak in the Salesforce Alpharetta Developer Group meeting. This is a 3 part blog series, explaining samples & demos I covered in that group meet. To get information about future sessions, you can join this group and also the chatter group to get content.
Let’s start with the basics.
What is Embedding?
Imagine you have a big box of crayons with many different colors. Each crayon is like a word or a picture. Now, suppose you want to organize these crayons so that similar colors are close to each other. For example, different shades of blue are grouped together, and so are the shades of red. This makes it easier for you to find and compare colors.
In the world of AI, embeddings do something similar but with words, pictures, or other kinds of information. Instead of crayons, we have lots of data, like words in a book or images. An embedding is a special method that sorts this data into groups of similar things.
For example, in a book, the words “happy” and “joyful” might be close together in this sorted space because they mean similar things. This helps AI models quickly understand and work with lots of information, like helping you find a book you might like or understanding what you mean when you talk to a computer.
So, embeddings are like a smart way of organizing a huge box of crayons (or data) so that similar things are close together, making it much easier and faster to use them for different tasks!
If we want to work with AI on Salesforce, very first step that needs to happen is to convert your data to embedding. In this case we would convert Salesforce data to embedding from lambda function using OpenAI API. Eventually, we would use some kind of library like langChain that can retrieve similar data to enrich prompts and get more contextual responses which otherwise would not be possible, this process is known as RAG – Retrieval-Augmented Generation.
Prerequisite
- Salesforce account with API access
- AWS account with Lambda and IAM access
- OpenAI API key
- Basic understanding of Python programming
AWS Lambda requires external libraries to be included as layers. You’ll need to create layers for OpenAI, numpy, and pandas
- Package your Python libraries in a ZIP file.
- Upload the ZIP file to Lambda Layers.
- Attach these layers to your Lambda function.
Complete Source Code & Video
Below source code, connects with Salesforce, fetches lead record and uses Open AI to convert data into embedding. It also shows how searched parameter can be compared with matched word using weightage
Few Observations
- I did not use SImple_Salesforce python library as it would need to be imported as a layer in lambda
- Environment variables can be created by navigating to the Configuration tab in the lambda
Below is the screenshot of the outcome
Leave a Reply