This topic covers the configuration of the Embeddings module of the Discourse AI plugin. It explains what embeddings are, how they’re used, and how to set them up.
Required user level: Administrator
Embeddings are a crucial component of the Discourse AI plugin, enabling features like related topics and semantic search. This guide will walk you through the setup and use of embeddings in your Discourse instance.
Summary
- Embeddings are pre-configured for hosted customers
- They power semantic features like related topics and semantic search
- Two provider options: Open Source (recommended) or OpenAI
- Various settings to customize embeddings behavior
What are embeddings?
Embeddings are numerical representations of text that capture semantic meaning. In Discourse, they’re used to:
- Generate “Related Topics” at the bottom of topic pages
- Enable semantic search functionality
Setting up embeddings
For hosted customers
If you’re a hosted customer, embeddings are pre-configured. You can simply enable the AI features that depend on them.
For self-hosted instances
If you’re self-hosting, refer to the Discourse AI self-hosted guide for detailed setup instructions.
Configuring embeddings
Navigate to your site settings to configure the following options:
- ai embeddings enabled: Turn the embeddings module on or off
- ai embeddings discourse service api endpoint: URL for the API (auto-configured for hosted customers)
- ai embeddings discourse service api key: API key (auto-configured for hosted customers)
- ai embeddings models: Select which models to use for generating embeddings
- ai embeddings semantic suggested model: Choose the model for semantic suggested topics
- ai embeddings generate for pms: Decide whether to generate embeddings for private messages
- ai embeddings semantic related topics enabled: Enable or disable the “Related Topics” feature
- ai embeddings pg connection string: Database connection string (auto-configured for hosted customers)
- ai openai api key: Your OpenAI API key (if using OpenAI as a provider)
- ** ai embeddings semantic search hyde mode**: The model used for keyword expansion during AI search.
Providers
Discourse AI supports two embedding providers:
- Open Source (recommended and default): Uses a collection of open-source models from SBERT
- OpenAI: Requires an OpenAI API key
Features
Related Topics
When enabled, a “Related Topics” section appears at the bottom of topic pages, linking to semantically similar discussions.
You can read more about using Related Topics in this guide.
Semantic Search
Embeddings power the semantic search option on the full-page search interface.
Semantic search leans on HyDE (Hypothetical Document Embedding). We expand the search term using a large language model you supply. Once expanded we convert the expanded search to a vector and look for similar topics. This technique adds some latency to search and improves results. When selecting a model for hyde, ai embeddings semantic search hyde mode
be sure to choose a fast model like Gemini Flash, Claude Haiku or GPT4o Mini.
Generating embeddings
Embeddings are generated automatically for new posts. To generate embeddings for existing content:
- Embeddings are created when a page is viewed if they’re missing
- Self-hosters can use the rake task
ai:embeddings:backfill
to generate embeddings for all topics
The rake task should only be used by experienced operators who can install required gems manually.
FAQs
Q: How are related topics determined?
A: Related topics are based solely on embeddings, which include the title, category, tags, and posts content.
Q: Can I exclude certain topics from related topics?
A: Yes, there’s a site setting to remove closed topics from the results.
Q: Do embeddings work for historical posts?
A: Yes, the system will automatically backfill embeddings for all your content.
Additional resources
Last edited by @sam 2024-09-01T23:57:59Z
Last checked by @hugh 2024-08-06T04:16:01Z
Check document
Perform check on document: