Skip to content

Commit 9d4a2b7

Browse files
authored
Merge branch 'main' into DS-4821b
2 parents 73a8dc3 + 6420844 commit 9d4a2b7

File tree

5 files changed

+223
-73
lines changed

5 files changed

+223
-73
lines changed

docs/AI-Search-Assistant.md

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Example: OpenAI GPT-4 Configured for Chat & RAG
7373
}
7474
```
7575

76+
For more details, see the **AI Search, Enterprise Edition** section: [Connecting to Enterprise GAI and LLMs](AI-Search#connecting-to-generative-ai-gai-and-large-language-models-llms).
77+
7678
## Launching Assistant
7779

7880
Once the AI provider is configured correctly, **Assistant should be accessible via a browser**.
@@ -81,9 +83,6 @@ For a default installation, go to: [http://localhost:8000/galaxy/chat](http://lo
8183

8284
![SWIRL Assistant discussion](images/swirl_40_chat_scop.png)
8385

84-
For more details, see the **AI Search, Enterprise Edition** section: [Connecting to Enterprise GAI and LLMs](AI-Search#connecting-to-generative-ai-gai-and-large-language-models-llms).
85-
86-
8786
## Listing Sources
8887

8988
Instruct the Assistant to: `List sources`
@@ -112,6 +111,84 @@ Queries information on 7 million companies worldwide, including number of employ
112111

113112
The `description` field can be up to 2k in length.
114113

114+
## Using Prompts
115+
116+
SWIRL Enterprise includes a set of pre-loaded, standard prompts. Each consiss of three key components:
117+
118+
| Field | Description |
119+
| ----- | ----------- |
120+
| `prompt` | The main body of the prompt. Use `{query}` to represent the SWIRL query. |
121+
| `note` | Text appended to search result data sent to the LLM for insight generation. |
122+
| `footer` | Additional instructions appended after the prompt and RAG data. This is ideal for formatting guidance. |
123+
124+
The name of the `prompt` has no importance. SWIRL uses the `tags` field to determine which prompt is used for a given function.
125+
126+
The following table presents the `tags` options:
127+
128+
| Tag | LLM Role |
129+
| --- | -------- |
130+
| chat | Used by AI Search Assistant for chat conversations, including company background; not technical |
131+
| chat-rag | Used by AI Search Assistant to answer questions and summarize data via RAG; somewhat technical |
132+
| search-rag | Used by AI Search, `Generate AI Insight` (RAG) switch, somewhat technical |
133+
134+
Note that there must be at least one `active` prompt for each of these tags for the relevant SWIRL features to work.
135+
136+
### Modifying the Standard Prompts
137+
138+
{.warning}
139+
**Warning: never modify the standard prompts!** Any such changes will be discarded when SWIRL updates.
140+
141+
Use the [Customizing Prompts](#customizing-the-ai-search-assistant-prompts) procedure instead.
142+
143+
### Customizing the AI Search Assistant Prompts
144+
145+
The following procedure below below to copy the standard prompts, modify them, then make them active.
146+
New prompts that you create won't be disturbed during upgrades.
147+
148+
1. Open [http://localhost:8000/swirl/prompts/](http://localhost:8000/swirl/prompts/)
149+
150+
2. Locate the `chat_rag_instructions_standard`, `chat_rag_standard` or `chat_rag_deeplink` prompts and note the `id`.
151+
152+
3. Add the `id` to the URL to view just that prompt.
153+
154+
4. Click the `Raw data` tab at the bottom of the page. Copy the entire JSON record to the clipboard.
155+
156+
5. Click the `HTML form` tab at the bottom of the page. Set `active` to `false`. Click `PUT` to save the change.
157+
158+
6. Go back to [http://localhost:8000/swirl/prompts/](http://localhost:8000/swirl/prompts/) and scroll to the bottom of the form.
159+
160+
7. Select the `Raw data` tab if necessary. Paste the prompt copied in step #4 into `Content:` block. **Do not hit `Put` yet**.
161+
162+
8. Remove the `id`, `owner`, `date_created` and `date_updated` fields. Change the `name` field to something descriptive. Also, make sure `active` is set to `true`. Finally, if you don't wish to share this prompt with other users, set `shared` to `false`. Feel free to hit `PUT` now to save the record.
163+
164+
9. Modify the `prompt` field, and change `SWIRL Corporation` to the name of your organization. We also recommend adding adding 2-3 sentences describing the organization as well. immediately afterwards.
165+
166+
For example:
167+
168+
```json
169+
{
170+
"prompt": "You are an expert online assistant and reference librarian working for **<your-company-name>. <Your-company-name> is located in <description> and operates in <industry> etc**... Your job is...
171+
}
172+
```
173+
174+
{: .warning }
175+
**Warning:** Removing important sections of any prompt such as variables like `{header}` and `{query}` may cause AI Insight generation to fail or not contain important features such as follow-up questions or citations.
176+
177+
10. Hit `PUT`. This will save the prompt.
178+
179+
![SWIRL Prompt Object](images/swirl_prompt_form.png)
180+
181+
## Restoring Standard Prompts
182+
183+
To go back to a standard prompt after creating a new one:
184+
185+
1. Edit the new prompt and set `active` to `false`.
186+
2. Edit the standard prompt and set `active` to `true`.
187+
188+
### Restoring All Prompts to Default
189+
190+
To restore all prompts to the default, refer to the [Admin Guide on Resetting Prompts](Admin-Guide.html#resetting-prompts).
191+
115192
## Advanced Querying
116193

117194
To enable the Assistant to query in advanced query languages like SQL, the elastic API or Mongo MQL, add an LLM generated instruction set to this structure, including:

docs/AI-Search.md

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -284,60 +284,99 @@ This ensures automatic updates for AI provider credentials, reducing manual inte
284284

285285
# Managing Prompts
286286

287-
## Default Prompts
287+
SWIRL Enterprise includes a set of pre-loaded standard prompts used when Generating AI Insights via RAG.
288288

289-
{: .warning }
290-
**Warning:** If you edit a default system prompt, your changes will be lost when SWIRL is updated.
289+
Each consiss of three key components:
290+
291+
| Field | Description |
292+
| ----- | ----------- |
293+
| `prompt` | The main body of the prompt. Use `{query}` to represent the SWIRL query. |
294+
| `note` | Text appended to search result data sent to the LLM for insight generation. |
295+
| `footer` | Additional instructions appended after the prompt and RAG data. This is ideal for formatting guidance. |
296+
297+
The name of the `prompt` has no importance. SWIRL uses the `tags` field to determine which prompt is used for a given function.
298+
299+
The following table presents the `tags` options:
291300

292-
View the default prompts at:
293-
[http://localhost:8000/swirl/prompts/](http://localhost:8000/swirl/prompts/)
301+
| Tag | LLM Role |
302+
| --- | -------- |
303+
| search-rag | Used by AI Search, `Generate AI Insight` (RAG) switch, somewhat technical |
304+
| chat | Used by AI Search Assistant for chat conversations, including company background; not technical |
305+
| chat-rag | Used by AI Search Assistant to answer questions and summarize data via RAG; somewhat technical |
294306

295-
## Creating New Saved Prompts
307+
Note that there must be at least one `active` prompt for each of these tags for the relevant SWIRL features to work.
296308

297-
To create a new saved prompt:
309+
### Modifying the Standard Prompts
310+
311+
{.warning}
312+
**Warning: never modify the standard prompts!** Any such changes will be discarded when SWIRL updates.
313+
314+
Use the [Customizing Prompts](#customizing-the-ai-search-rag-prompt) procedure instead.
315+
316+
### Customizing the AI Search RAG Prompt
317+
318+
The following procedure below below to copy the standard prompts, modify them, then make them active.
319+
New prompts that you create won't be disturbed during upgrades.
298320

299321
1. Open [http://localhost:8000/swirl/prompts/](http://localhost:8000/swirl/prompts/)
300-
2. Use the form at the bottom of the page to create a new prompt **or** paste raw JSON and click `POST`.
301322

302-
**Example: Creating a Pirate-Themed Prompt**
323+
2. Locate the `search_rag_standard` or, if using [Deep Linking](./User-Guide-Enterprise.md#deep-linked-citations) `search_rag_deeplink` prompt, and note the `id`.
324+
325+
3. Add the `id` to the URL to view just that prompt.
326+
327+
4. Click the `Raw data` tab at the bottom of the page. Copy the entire JSON record to the clipboard.
328+
329+
5. Click the `HTML form` tab at the bottom of the page. Set `active` to `false`. Click `PUT` to save the change.
303330

304-
Modify the default prompt to generate responses in pirate-speak:
331+
6. Go back to [http://localhost:8000/swirl/prompts/](http://localhost:8000/swirl/prompts/) and scroll to the bottom of the form.
305332

333+
7. Select the `Raw data` tab if necessary. Paste the prompt copied in step #4 into `Content:` block. **Do not hit `Put` yet**.
334+
335+
8. Remove the `id`, `owner`, `date_created` and `date_updated` fields. Change the `name` field to something descriptive. Also, make sure `active` is set to `true`. Finally, if you don't wish to share this prompt with other users, set `shared` to `false`. Feel free to hit `PUT` now to save the record.
336+
337+
9. Modify the `prompt`, `note` and/or `footer` as needed, while retaining all critical instructions. For example, to instruct the LLM to use pirate-speak:
306338
```json
307339
{
308-
"name": "pirate",
340+
"name": "search_rag_standard_pirate",
309341
"...": "... etc ...",
310342
"footer": "--- Final Instructions ---
311343
In your response, pretend you are a pirate comedian, but keep it clean!",
312344
"tags": ["search-rag"]
313345
}
314346
```
315347

316-
This will produce:
317-
348+
10. Hit `PUT`. This will save the prompt.
318349
![SWIRL Prompt Object](images/swirl_prompt_form.png)
319350

320-
## Specifying a Saved Prompt in a Query
351+
{: .warning }
352+
**Warning:** Removing important sections of any prompt such as variables like `{header}` and `{query}` may cause AI Insight generation to fail or not contain important features such as follow-up questions or citations.
353+
354+
## Specifying a Saved Prompt when Generating AI Insights
355+
356+
There are two ways to select a saved prompt:
357+
358+
1. Use the prompt selector on the AI Search form:
359+
![SWIRL AI Search Form w/Prompt Selector](./images/swirl_40_search_prompts.png)
321360

322-
Test a saved prompt using the **prompt operator**:
361+
2. Use the **prompt operator** in your query. For example:
323362

324363
```
325364
swirl AI Search prompt:pirate
326365
```
327366

328-
The response should be generated in pirate-speak:
329-
367+
In either case, the response is generated in pirate-speak as the prompt instructs:
330368
![SWIRL RAG response in pirate speak](images/swirl_prompt_pirate.png)
331369

332-
## Understanding Saved Prompts
370+
## Restoring Standard Prompts
333371

334-
SWIRL prompts consist of three key components:
372+
To go back to a standard prompt after creating a new one:
335373

336-
| Field | Description |
337-
| ----- | ----------- |
338-
| `prompt` | The main body of the prompt. Use `{query}` to represent the SWIRL query. |
339-
| `note` | Text appended to RAG data chunks, annotated by the [Text Analyzer](#text-summarization). |
340-
| `footer` | Additional instructions appended after the prompt and RAG data. This is ideal for formatting guidance. |
374+
1. Edit the new prompt and set `active` to `false`.
375+
2. Edit the standard prompt and set `active` to `true`.
376+
377+
### Restoring All Prompts to Default
378+
379+
To restore all prompts to the default, refer to the [Admin Guide on Resetting Prompts](https://docs.swirlaiconnect.com/Admin-Guide#resetting-prompts).
341380

342381
## Using a Prompt in a Query Processor or Connector
343382

docs/Developer-Guide.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,9 @@ To address this, use the **[DateFindingResultProcessor](#find-dates-in-bodytitle
200200

201201
## Use an LLM to Rewrite Queries
202202

203-
SWIRL AI Search supports **query rewriting** using `ChatGPTQueryProcessor` (for the Community edition) or the `GenAIQueryProcessor` (for Enterprise).
203+
SWIRL AI Search supports **query rewriting** using an LLM. To set this up, add the `GenAIQueryProcessor` to some `SearchProvider.query_processors` list.
204204

205-
To enable it, add the processor to `SearchProvider.query_processors`.
206-
207-
For details, see: [Developer Reference - Query Processors](./Developer-Reference#query-processors).
205+
For details, see: [Developer Reference - GenAIQueryProcessor](./Developer-Reference.md#genai-and-chatgpt-connectors)
208206

209207
## Adjust `swirl_score` for Starred Results in Galaxy UI
210208

@@ -214,7 +212,7 @@ For details, see: [Developer Reference - Query Processors](./Developer-Reference
214212

215213
**SWIRL Enterprise Edition **
216214
- Configured via `"minimumConfidenceScore"` in `static/api/config/default`.
217-
- Default: `0.7`. Increase this to reduce starred results.
215+
- Default: `0.7`. Increase this to reduce the number of starred results and use only highly relevant results.
218216

219217
![SWIRL AI Search 4.0 Results](images/swirl_40_results.png)
220218

docs/Developer-Reference.md

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,13 @@ The included [BigQuery SearchProvider](https://github.com/swirlai/swirl-search/b
297297

298298
More information: [BigQuery Documentation](https://cloud.google.com/bigquery/docs)
299299

300-
## GenAI and ChatGPT Connectors
300+
## GenAI Connectors
301301

302-
SWIRL includes connectors that can be used to obtain direct answers from LLMs, as if they were regular SearchProviders. The connector is the `ChatGPTConnector` (for the Community edition) or the `GenAIConnector` (for Enterprise).
303-
304-
Both connectors return at most one result.
302+
SWIRL includes the `GenAIConnector` which can ask for direct answers from LLMs, as if they were regular SearchProviders. It returns at most one result.
305303

306304
The included [SearchProvider](https://github.com/swirlai/swirl-search/blob/main/SearchProviders/gen_ai.json) is pre-configured with a "Tell me about: ..." prompt.
307305

306+
308307
```json
309308
{
310309
"name": "GenAI - OpenAI",
@@ -316,7 +315,7 @@ The included [SearchProvider](https://github.com/swirlai/swirl-search/blob/main/
316315
"query_processors": [
317316
"AdaptiveQueryProcessor"
318317
],
319-
"query_mappings": "",
318+
"query_mappings": "PROMPT='Tell me about: {query_to_provider}'",
320319
"result_processors": [
321320
"GenericResultProcessor",
322321
"CosineRelevancyResultProcessor"
@@ -332,40 +331,37 @@ The included [SearchProvider](https://github.com/swirlai/swirl-search/blob/main/
332331
}
333332
```
334333

335-
The `Question` and `GenAI` SearchProvider Tags enable targeted queries. For example:
336-
337-
```shell
338-
Question: Tell me about knowledge management software?
339-
```
340-
341334
### Setting the GenAI Prompt or Role
342335

343-
The following tags adjust the prompt or role passed to GenAI.
336+
The following `query_mappings` **including quotes** adjust the prompt or role passed to GenAI.
344337

345338
* `CHAT_QUERY_REWRITE_PROMPT`: Customizes the prompt used to refine the query.
346339

347340
```json
348-
"CHAT_QUERY_REWRITE_PROMPT:Write a more precise query of similar length to this: {query_string}"
341+
"CHAT_QUERY_REWRITE_PROMPT: Write a more precise query of similar length to this: {query_to_provider}"
349342
```
350343

351344
* `CHAT_QUERY_REWRITE_GUIDE`: Overrides the `system` role.
352345

353346
```json
354-
"CHAT_QUERY_REWRITE_GUIDE:You are a helpful assistant that responds like a pirate captain"
347+
"CHAT_QUERY_REWRITE_GUIDE: You are a helpful assistant that responds like a pirate captain"
355348
```
356349

357350
* `CHAT_QUERY_DO_FILTER`: Enables/disables internal filtering of LLM responses.
358351

359352
```json
360-
"CHAT_QUERY_DO_FILTER:false"
353+
"CHAT_QUERY_DO_FILTER: false"
361354
```
362355

363-
The following `query_mapping` adjusts the default role passed to GenAI:
356+
For example:
364357

365-
```shell
366-
"query_mappings": "PROMPT='Tell me about: {query_to_provider}',CHAT_QUERY_REWRITE_GUIDE='You are a helpful assistant that responds like a pirate captain'",
358+
```json
359+
"query_mappings": "CHAT_QUERY_REWRITE_PROMPT='Tell me about: {query_to_provider}',CHAT_QUERY_REWRITE_GUIDE='You are a helpful assistant that talks like a pirate captain but keeps it clean!'",
367360
```
368361

362+
{.warning}
363+
Do not use commas inside of a prompt passed in this manner.
364+
369365
# Elastic & OpenSearch
370366

371367
The [Elastic](https://github.com/swirlai/swirl-search/blob/main/swirl/connectors/elastic.py) and [OpenSearch](https://github.com/swirlai/swirl-search/blob/main/swirl/connectors/opensearch.py) Connectors use each engine's Python client.
@@ -917,22 +913,15 @@ Query Processors modify queries. The field they operate on depends on where they
917913
| Processor | Description | Notes |
918914
| ---------- | ---------- | ---------- |
919915
| **AdaptiveQueryProcessor** | Rewrites queries based on `query_mappings` for a given SearchProvider | Not for `pre_query_processors` |
920-
| **ChatGPTQueryProcessor** | Uses OpenAI to rewrite queries, making them broader, more specific, boolean, or in another language | Community edition only |
921-
| **GenAIQueryProcessor** | Uses an LLM to rewrite queries, making them broader, more specific, boolean, or in another language | Enterprise edition only |
916+
| **GenAIQueryProcessor** | Uses an LLM to rewrite queries, making them broader, more specific, boolean, or in another language | |
922917
| **GenericQueryProcessor** | Removes special characters from queries | |
923918
| **SpellcheckQueryProcessor** | Uses [TextBlob](https://textblob.readthedocs.io/en/dev/quickstart.html#spelling-correction) to correct spelling errors | Best used in `SearchProvider.query_processors`; avoid with Google PSE |
924919
| **NoModQueryProcessor** | Removes only leading SearchProvider Tags, leaving query terms unchanged | For repositories allowing non-search characters (e.g., brackets) |
925920
| **RemovePIIQueryProcessor** | Removes PII entities from queries without replacing them | |
926921

927922
## GenAIQueryProcessor
928923

929-
The `GenAIQueryProcessor` calls an LLM with the user's query and a custom prompt to enable rewriting. For example this processor can:
930-
931-
* Translate queries between languages
932-
* Rewrite queries as booleans
933-
* Perform phrase detection
934-
935-
And much more.
924+
The `GenAIQueryProcessor` calls an LLM with the user's query and a custom prompt to enable rewriting, translation phrase detection and much more.
936925

937926
### Configuring the SearchProvider
938927

@@ -954,18 +943,20 @@ To alter the query sent to all Searchproviders, add it to the `search.pre_query_
954943
}
955944
```
956945

957-
Note: this requires calling the Swirl Search API and is not supported via Galaxy.
946+
Note that the example above only applies to calling the SWIRL API. Please [contact support](#support) for instructions on how to configure this behavior with the Galaxy UI.
958947

959948
### Configuring the QueryProcessor
960949

961-
The GenAIQueryProcessor supports the same tags and configuration options as the [GenAIConnector](#setting-the-genai-prompt-or-role).
950+
The GenAIQueryProcessor supports the same tags and configuration options as the [GenAIConnector](#setting-the-genai-prompt-or-role) but using a colon (':') as a delimeter.
962951

963952
For example:
964953

965954
```json
966955
"tags": [
967-
"PROMPT='Translate this query to japanese, if necessary: {query_string}"
968-
],
956+
"CHAT_QUERY_REWRITE_PROMPT:If this query is in Japanese, tokenize it, and output ONLY the tokenized japanese, NOTHING ELSE -> {query_string}",
957+
"CHAT_QUERY_REWRITE_GUIDE:You are a speedy tokenizer!",
958+
"CHAT_QUERY_DO_FILTER:False"
959+
],
969960
```
970961

971962
# Result Processors

0 commit comments

Comments
 (0)