# Semantic Search API

**URL:** https://meta.discourse.org/t/semantic-search-api/342825
**Category:** Support
**Tags:** ai
**Created:** [December 17, 2024, 5:42am UTC](https://meta.discourse.org/t/semantic-search-api/342825 "2024-12-17T05:42:34Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [December 17, 2024, 5:42am UTC](https://meta.discourse.org/t/semantic-search-api/342825/1 "2024-12-17T05:42:34Z")

</div>

How can we access semantic search through the API?

search.json does not seem to have semantic (even though, I remember they did at some point?)

`discourse-ai/embeddings/semantic-search?q=` is called after search.json, good results are correct when I open the URL including query I just did.

But if I `discourse-ai/embeddings/semantic-search?q=differentQuery` directly the results do not make sense at all.

What do I miss here?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 17, 2024, 6:31am UTC](https://meta.discourse.org/t/semantic-search-api/342825/2 "2024-12-17T06:31:14Z")

</div>

You can do a pure embeddings search using:

`https://DOMAIN/discourse-ai/embeddings/semantic-search.json?hyde=false&q=....`

That disables the hyde portion so it is rate limited a lot less aggressively.

Additionally ideally use an api key for the call which relaxes a lot of the limits.

---

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [December 17, 2024, 6:41am UTC](https://meta.discourse.org/t/semantic-search-api/342825/3 "2024-12-17T06:41:25Z")

</div>

Thanks, this works!

> [@sam](#):
>
> Additionally ideally use an api key for the call which relaxes a lot of the limits.

I whitelisted my IP’s from ratelimiting in app.yml, I think I read somewhere that this was also a solution to bypass ratelimits if I’m correct.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 17, 2024, 6:43am UTC](https://meta.discourse.org/t/semantic-search-api/342825/4 "2024-12-17T06:43:48Z")

</div>

> [@MarcP](#):
>
> I whitelisted my IP’s from ratelimiting in app.yml, I think I read somewhere that this was also a solution to bypass ratelimits if I’m correct.

Not really, search limits are generally implemented in the app, skipping hyde is critical here:

> <https://github.com/discourse/discourse-ai/blob/ca800f7aa3e6efcd8c7c9d8aef87ea8b2c548184/app/controllers/discourse_ai/embeddings/embeddings_controller.rb#L10-L11>

You only get 4 hyde queries a minute (where we expand the search term for you), you get up to 100 non hyde ones (provided other rate limits are relaxed)

---

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [December 17, 2024, 6:46am UTC](https://meta.discourse.org/t/semantic-search-api/342825/5 "2024-12-17T06:46:52Z")

</div>

> [@sam](#):
>
> skipping hyde is critical here

I will pass this param for sure.

My question was actually: passing API key is effectively the same as excluding an IP from ratelimits? Or did you mean hyde=false only works IF an API key is passed?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 17, 2024, 6:49am UTC](https://meta.discourse.org/t/semantic-search-api/342825/6 "2024-12-17T06:49:45Z")

</div>

both are unrelated. api has different knobs for rate limits, you can relax it more than other parts of the app in global settings

---

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [December 17, 2024, 6:59am UTC](https://meta.discourse.org/t/semantic-search-api/342825/7 "2024-12-17T06:59:20Z")

</div>

Got it, the app.yml flag I was talking about seems to lift nginx ratelimits (`DISCOURSE_MAX_REQS_PER_IP_EXCEPTIONS`)

The topic below made it a bit more clear to me:

> [@Available settings for global rate limits and throttling](https://meta.discourse.org/t/available-settings-for-global-rate-limits-and-throttling/78612):
>
> Discourse ships with 3 different global rate limits that can be configured by site admins. Global per-ip rate limits These limits apply to every unique IP address that hits the Discourse application. (files that are served directly from the filesystem or the CDN are excluded) By default this rate limit is enabled, you may disable it or set it to a reporting mode. DISCOURSE\_MAX\_REQS\_PER\_IP\_MODE : default block, this rate limit applies out of the box. (other options are warn, warn+block, and n…

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [January 16, 2025, 6:59am UTC](https://meta.discourse.org/t/semantic-search-api/342825/8 "2025-01-16T06:59:50Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
