Hosts Hugging-Face sentence-transformers, which are specifically trained for embedding creation, on local host (127.0.0.1) at port 3000.
pip install -r requirements.txt
python3 API.py
Destination: localhost:3000/vectorEmbeddings
Method: POST
Body: JSON object
fetch('http://localhost:3000/vectorEmbeddings', {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
product_name: "Smartphone X",
product_description: "A high-end smartphone with a powerful processor",
product_category: "Electronics",
product_cost: 799.99,
product_id: "P1234"
})
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => { console.log(data) })
.catch(error => { console.error('Error:', error) });
Returns a JSON object with the same details as the POST body with two new keys:
- vector: Embedding Vector
- inferenceTime: Time taken for the model to generate the embedding vector