Tutorial
Text Processing
8 min reading

How to do Semantic Search with JavaScript?

Summarize this article with:

summary
  • 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.

‍

Semantic Search API result on Eden AI

‍

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.

‍

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.

Eden AI platform - Get your API key

‍

‍

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.

Multiple AI engines in one API

‍

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.

‍

FAQ — do Semantic Search with JavaScript

You need an API key from your chosen AI provider. Eden AI lets you access multiple providers with a single key, removing the need for separate vendor accounts.
Any language that supports HTTP requests works — Python, JavaScript, PHP, Ruby, Go, and more. Ready-to-use code snippets are available for the most common languages.
Most developers complete a basic integration in under an hour using standardized API endpoints and ready-to-use code examples.
Implement exponential backoff for rate limit errors and use try-catch blocks for network failures. Eden AI's built-in fallback routing automatically redirects requests if a provider is unavailable.
Eden AI supports GDPR-compliant provider filtering and does not store or reuse your data, ensuring compliance with European privacy regulations.

Similar articles

An operator steers a thread of prompt blocks toward the GPU tower whose cache blocks are still lit, away from a tower where they have faded.
Tutorial
Generative AI
Should You Switch to SageMaker KV Cache-Aware Routing?
11/17/2026
·
Written byClément Moreau
Fireworks AI and Notion logos connected by a simple data path, representing third-party AI data exposure.
Tutorial
Generative AI
Fireworks AI Breach: How to Limit Third-Party AI Data Exposure
11/12/2026
·
Written byClément Moreau
Tutorial
Generative AI
From Shadow AI to Governed AI in 30 Days: A Practical Playbook
10/28/2026
·
Written byTaha Zemmouri
let’s start

Start building with Eden AI

A single interface to integrate the best AI technologies into your products.