discourse-ai/assets/javascripts/discourse
Sam 32b3004ce9
FEATURE: Add Question Consolidator for robust Upload support in Personas (#596)
This commit introduces a new feature for AI Personas called the "Question Consolidator LLM". The purpose of the Question Consolidator is to consolidate a user's latest question into a self-contained, context-rich question before querying the vector database for relevant fragments. This helps improve the quality and relevance of the retrieved fragments.

Previous to this change we used the last 10 interactions, this is not ideal cause the RAG would "lock on" to an answer. 

EG:

- User: how many cars are there in europe
- Model: detailed answer about cars in europe including the term car and vehicle many times
- User: Nice, what about trains are there in the US

In the above example "trains" and "US" becomes very low signal given there are pages and pages talking about cars and europe. This mean retrieval is sub optimal. 

Instead, we pass the history to the "question consolidator", it would simply consolidate the question to "How many trains are there in the United States", which would make it fare easier for the vector db to find relevant content. 

The llm used for question consolidator can often be less powerful than the model you are talking to, we recommend using lighter weight and fast models cause the task is very simple. This is configurable from the persona ui.

This PR also removes support for {uploads} placeholder, this is too complicated to get right and we want freedom to shift RAG implementation. 

Key changes:

1. Added a new `question_consolidator_llm` column to the `ai_personas` table to store the LLM model used for question consolidation.

2. Implemented the `QuestionConsolidator` module which handles the logic for consolidating the user's latest question. It extracts the relevant user and model messages from the conversation history, truncates them if needed to fit within the token limit, and generates a consolidated question prompt.

3. Updated the `Persona` class to use the Question Consolidator LLM (if configured) when crafting the RAG fragments prompt. It passes the conversation context to the consolidator to generate a self-contained question.

4. Added UI elements in the AI Persona editor to allow selecting the Question Consolidator LLM. Also made some UI tweaks to conditionally show/hide certain options based on persona configuration.

5. Wrote unit tests for the QuestionConsolidator module and updated existing persona tests to cover the new functionality.

This feature enables AI Personas to better understand the context and intent behind a user's question by consolidating the conversation history into a single, focused question. This can lead to more relevant and accurate responses from the AI assistant.
2024-04-30 13:49:21 +10:00
..
admin FEATURE: Add Question Consolidator for robust Upload support in Personas (#596) 2024-04-30 13:49:21 +10:00
components FEATURE: Add Question Consolidator for robust Upload support in Personas (#596) 2024-04-30 13:49:21 +10:00
connectors FIX: Ask AI highlight fixes (#562) 2024-04-08 11:00:03 -07:00
controllers DEV: Use the new controller/period component for the dashboard (#435) 2024-01-19 13:27:33 +01:00
lib DEV: replace diffhtml with morphlex (#555) 2024-04-04 16:00:16 +02:00
routes DEV: Move admin routes + templates to admin/assets/javascripts/ path (#545) 2024-03-25 09:58:53 +10:00
services FEATURE: AI Quick Semantic Search (#501) 2024-03-08 13:02:50 -03:00
templates DEV: Move admin routes + templates to admin/assets/javascripts/ path (#545) 2024-03-25 09:58:53 +10:00
admin-discourse-ai-plugin-route-map.js FEATURE: Improve admin plugin UI and use new plugins show route (#512) 2024-03-21 14:29:56 +10:00
admin-discourse-ai-route-map.js FEATURE: Expose sentiment classifications via the admin dashboard. (#284) 2023-11-08 10:50:37 -03:00
discourse-ai-shared-conversation-show-route-map.js FEATURE: Share conversations with AI via a URL (#521) 2024-03-12 16:51:41 +11:00