# Feature extraction with Inference API in Javascript

**URL:** <https://discuss.huggingface.co/t/feature-extraction-with-inference-api-in-javascript/110115>\
**Category:** Beginners\
**Created:** [October 4, 2024, 10:57am UTC](https://discuss.huggingface.co/t/feature-extraction-with-inference-api-in-javascript/110115 "2024-10-04T10:57:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![laurafbec](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@laurafbec](https://discuss.huggingface.co/u/laurafbec)\
**Post date:** [October 4, 2024, 10:57am UTC](https://discuss.huggingface.co/t/feature-extraction-with-inference-api-in-javascript/110115/1 "2024-10-04T10:57:28Z")

</div>

Hi everyone, I need to use a model for feature extraction through the Inference API in Javascript.

Using the examples described in [Parameters](https://huggingface.co/docs/api-inference/parameters?code=js#feature-extraction-task), by using this code:

```auto
async function query(data) {
    const response = await fetch(
        "https://api-inference.huggingface.co/models/sentence-transformers/all-mpnet-base-v2",
        {
            method: "POST",
            headers: {
                Authorization: `Bearer hf_XXXXXXXXXXXXXXXXXX`,
                "Content-Type": "application/json"
            },
            body: JSON.stringify(data),
        }
    );
    const result = await response.json();
    return result;
}
query({
    inputs: "Can you please let us know more details about your "
}).then((response) => {
    console.log(JSON.stringify(response, null, 2));
});

```

I’m getting the error

```auto
{
  "error": [
    "Input should be a valid dictionary or instance of SentenceSimilarityInputsCheck: received `Can you please let us know more details about your ` in `parameters`"
  ]
}

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [October 4, 2024, 11:48am UTC](https://discuss.huggingface.co/t/feature-extraction-with-inference-api-in-javascript/110115/2 "2024-10-04T11:48:04Z")

</div>

Maybe the error is more troublesome than I thought. Maybe something is wrong with the model repo settings. Try another model if you can.

> <https://github.com/langchain-ai/langchainjs/issues/1083>
>
> this error accrues while using HuggingFaceInferenceEmbeddings with NOT default m…odel.
> 
> error - unhandledRejection: Error: SentenceSimilarityInputsCheck expected dict not list: \`\_\_root\_\_\` in \`parameters\`
> at HfInference.request (file:///C:/Users/USER/Documents/GitHub/chatbot-ui/node\_modules/@huggingface/inference/dist/index.mjs:425:13)
> at process.processTicksAndRejections (node:internal/process/task\_queues:95:5)
> at async HfInference.featureExtraction (file:///C:/Users/USER/Documents/GitHub/chatbot-ui/node\_modules/@huggingface/inference/dist/index.mjs:264:17)
> at async RetryOperation.\_fn (C:\\Users\\USER\\Documents\\GitHub\\chatbot-ui\\node\_modules\\p-retry\\index.js:50:12) {
> attemptNumber: 7,
> retriesLeft: 0
> }
> 
> all working fine if i use OpenAI embedding or HuggingFace default model

> [@SentenceSimilarityInputsCheck expected dict not list: \`\_\_root\_\_\` in \`parameters\`](https://discuss.huggingface.co/t/sentencesimilarityinputscheck-expected-dict-not-list-root-in-parameters/39715):
>
> Hi, I’m new to ML/AI and haven’t experimented much yet. I am a experienced developer in my day job though. I’m having a few issues I’m hoping someone can help me with. My main goal is the following. I’m trying to write a bot that crawls a website, vectorizes all the text and stores this in pinecone db. Then the user can ask a question, and I query pinecone db for text that hopefully answers their question and feed that to chatgpt for it to answer the question. Everything seems to be working bu…

---

<div class="post-metadata">

**Author:** ![laurafbec](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@laurafbec](https://discuss.huggingface.co/u/laurafbec)\
**Post date:** [October 4, 2024, 12:21pm UTC](https://discuss.huggingface.co/t/feature-extraction-with-inference-api-in-javascript/110115/3 "2024-10-04T12:21:00Z")

</div>

Thanks @John6666!!! I’ve read it’s due to the pipeline\_tag property of the model. It seems it must have the value ‘feature-extraction’.

This model worked to me:

```auto
async function query(data) {
	const response = await fetch(
		"https://api-inference.huggingface.co/models/facebook/bart-base",
		{
			headers: {
				Authorization: "Bearer hf_XXXXXXXXXXXX",
				"Content-Type": "application/json",
			},
			method: "POST",
			body: JSON.stringify(data),
		}
	);
	const result = await response.json();
	return result;
}

query({"inputs": "Today is a sunny day and I will get some ice cream."}).then((response) => {
	console.log(JSON.stringify(response));
});

```

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [October 4, 2024, 12:37pm UTC](https://discuss.huggingface.co/t/feature-extraction-with-inference-api-in-javascript/110115/4 "2024-10-04T12:37:34Z")

</div>

Wow. Was it a hit?  
It’s going to take a while for us to report back to the model authors and get them to fix it.  
It’s faster if you have a usable model.

---

<div class="post-metadata">

**Author:** ![laurafbec](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@laurafbec](https://discuss.huggingface.co/u/laurafbec)\
**Post date:** [October 7, 2024, 6:36am UTC](https://discuss.huggingface.co/t/feature-extraction-with-inference-api-in-javascript/110115/5 "2024-10-07T06:36:40Z")

</div>

Let me know their answer!! Thanks again!

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [October 7, 2024, 6:55am UTC](https://discuss.huggingface.co/t/feature-extraction-with-inference-api-in-javascript/110115/6 "2024-10-07T06:55:24Z")

</div>

Oh, no, I’m not reporting it because it seems to have worked. It’s hard when it doesn’t work …
