Summarize this article with:
- Semantic Search API uses Natural Language Processing (NLP) and Machine Learning techniques to understand the intent of the user and the context of the query, and then returns results that are semantically...
- The first step is to set Axios, a promise-based HTTP client for the browser and Node.js, that will allow you to call Eden AI API.
- Developers can do Semantic Search with JavaScript using a REST API that accepts standard inputs and returns structured JSON responses.
- The integration works with Python, JavaScript, PHP, and any HTTP-capable language with minimal setup.
- A multi-provider API removes the need to manage separate accounts and authentication per vendor.
In this tutorial, you will learn how to use Semantic Search API in 5 minutes using JavaScript. Eden AI provides an easy and developer-friendly API that allows you to search information into texts.
What is Semantic Search?
Semantic Search API uses Natural Language Processing (NLP) and Machine Learning techniques to understand the intent of the user and the context of the query, and then returns results that are semantically related to the query. It can provide a more effective result than traditional keyword-based search methods by focusing on concepts and ideas rather than basic matching keywords.

Get Started with Semantic Search API using JavaScript
The first step is to set Axios, a promise-based HTTP client for the browser and Node.js, that will allow you to call Eden AI API.
.png)
How to use Semantic Search API with JavaScript
You are now ready to process text into Eden AI Search API. You can access the list of languages supported in our documentation here.
1. Get a Semantic Search API Key on Eden AI
To perform Semantic Search, you'll need to create an account on Eden AI for free. Then, you will be able to get your API key directly from the homepage with free credits offered by Eden AI.
.png)
2. Let’s Search Information into Text
Now that you have initialized the required JavaScript modules and got your API key, you will be able to search information into your text. With Eden AI, you can choose from a wide range of engines you want for Semantic Search. You can access the list of Semantic Search providers available on Eden AI directly on our documentation.
Semantic search now goes through embeddings: Eden AI turns the query and your texts into vectors with its OpenAI-compatible embeddings endpoint, and the most relevant texts are those whose vectors are closest to the query (cosine similarity). Here is the JavaScript code to configure the request:
const texts = [
"Barack Hussein Obama II is an American politician and attorney who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party",
"The White House is the official residence and workplace of the president of the United States. It is located at 1600 Pennsylvania Avenue NW in Washington, D.C",
];
const query = "The President";
const options = {
method: "POST",
url: "https://api.edenai.run/v3/embeddings",
headers: {
authorization: "Bearer Your_API_Key",
},
data: {
model: "openai/text-embedding-3-small", // or google/gemini-embedding-001, mistral/mistral-embed...
input: [query, ...texts], // the query first, then the texts to search
},
};
Then, you'll need to launch the request, compare each text with the query and print the result:
// Cosine similarity: the closer to 1, the closer the meanings
const cosine = (a, b) => {
let dot = 0, normA = 0, normB = 0;
for (let i = 0; i < a.length; i++) {
dot += a[i] * b[i];
normA += a[i] * a[i];
normB += b[i] * b[i];
}
return dot / Math.sqrt(normA * normB);
};
axios
.request(options)
.then((response) => {
const [queryVector, ...textVectors] = response.data.data.map((item) => item.embedding);
const results = textVectors
.map((vector, document) => ({ document, score: cosine(queryVector, vector) }))
.sort((a, b) => b.score - a.score);
console.log(results);
});
Here is an example of a Semantic Search result, where document is the position of the text in your list and a higher score means a closer meaning:
[
{ document: 0, score: 0.40992077884948125 },
{ document: 1, score: 0.3925218882891552 }
]
Benefits of using Semantic Search API with Eden AI
As you can see, using Semantic Search with Eden AI API is quick and easy.
.gif)
Save time and cost
We offer a unified API for all providers: simple and standard to use, with a quick switch between providers and an access to the specific features of each provider.
Easy to integrate
The JSON output format is the same for all suppliers thanks to Eden AI's standardisation work. The response elements are also standardised thanks to Eden AI's powerful matching algorithms.
Customization
With Eden AI you have the possibility to integrate a third-party platform: we can quickly develop connectors. To go further and customize your Semantic Search request with specific parameters, check out our documentation.
.png)
.jpg)

