> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/ai/semantic-search.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Semantic search

**Semantic search** finds knowledge-base chunks whose meaning is closest to your query — not just keyword matches. Use `search` before composing a custom prompt, or rely on `useKnowledgeBase: true` in `sendAI` for automatic retrieval.

## Method

```
search({
  senderId: string,
  query: string,
  limit?: number,
  minSimilarity?: number,    // 0.0 – 1.0
  filterbySource?: string,   // matches metadata.source
})
```

| Parameter        | Description                                    |
| ---------------- | ---------------------------------------------- |
| `query`          | Natural-language question or keywords          |
| `limit`          | Max results (default server-side)              |
| `minSimilarity`  | Drop hits below this score                     |
| `filterbySource` | Filter by `metadata.source` from `addDocument` |

{% hint style="info" %}
Use **`transport: "http"`**. `search` returns ranked hits directly from the async call.
{% endhint %}

`search` uses the vector store and embedding model on `notifier.serverConfig`. Pass `vectorStore` or `embedding` on the call to override that for one query. Keyword and hybrid search run on Postgres.

→ [Vector stores and embeddings](https://dnotifier.gitbook.io/product-docs/ai/vector-stores.md)

## Search vs `useKnowledgeBase`

| Approach                     | Control                           | Complexity                                                                                             |
| ---------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------ |
| **`search` then `sendAI`**   | You choose which chunks to inject | Higher — custom prompts                                                                                |
| **`useKnowledgeBase: true`** | Platform retrieves automatically  | Lower — see [Chat-style messages](https://dnotifier.gitbook.io/product-docs/ai/chat-style-messages.md) |

## Tuning tips

| Goal                  | Suggestion                                      |
| --------------------- | ----------------------------------------------- |
| Fewer false positives | Raise `minSimilarity` (e.g. `0.7`)              |
| Broader recall        | Lower `minSimilarity` (e.g. `0.3`)              |
| Scoped search         | Set `filterbySource` matching `metadata.source` |
| Debug empty results   | Verify documents exist via `listDocuments`      |

## Language guides

| Language                | Guide                                                                                                             |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------- |
| JavaScript / TypeScript | [javascript-typescript.md](https://dnotifier.gitbook.io/product-docs/ai/semantic-search/javascript-typescript.md) |
| Dart / Flutter          | [dart-flutter.md](https://dnotifier.gitbook.io/product-docs/ai/semantic-search/dart-flutter.md)                   |
| Python                  | [python.md](https://dnotifier.gitbook.io/product-docs/ai/semantic-search/python.md)                               |

## Next steps

* [**Manage documents**](https://dnotifier.gitbook.io/product-docs/ai/manage-documents.md) — Index content first
* [**Vector stores and embeddings**](https://dnotifier.gitbook.io/product-docs/ai/vector-stores.md) — Choose the store and embedding model
* [**Example: RAG bot**](https://dnotifier.gitbook.io/product-docs/ai/example-rag-bot.md) — End-to-end Q\&A
