Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/components/AiResponse/ChatInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
chatGenerationStatePubSub,
chatInputPubSub,
followUpQuestionPubSub,
getSettings,
imageSearchResultsPubSub,
queryPubSub,
settingsPubSub,
Expand All @@ -34,6 +33,7 @@ import {
import { generateRelatedSearchQuery } from "@/modules/relatedSearchQuery";
import { searchImages, searchText } from "@/modules/search";
import { generateChatResponse } from "@/modules/textGeneration";
import { searchResultsToConsider } from "@/modules/textGenerationUtilities";
import type { ChatMessage } from "@/modules/types";
import ChatHeader from "./ChatHeader";
import ChatInputArea from "./ChatInputArea";
Expand Down Expand Up @@ -298,7 +298,7 @@ export default function ChatInterface({
);

updateLlmTextSearchResults(
freshResults.slice(0, getSettings().searchResultsToConsider),
freshResults.slice(0, searchResultsToConsider),
);

if (uniqueFreshResults.length > 0) {
Expand Down
27 changes: 1 addition & 26 deletions client/components/Pages/Main/Menu/AISettings/AISettingsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Select, Slider, Stack, Switch, Text, TextInput } from "@mantine/core";
import { Select, Stack, Switch, Text, TextInput } from "@mantine/core";
import { useForm } from "@mantine/form";
import { notifications } from "@mantine/notifications";
import { usePubSub } from "create-pubsub/react";
import { useMemo } from "react";
import { requestNotificationPermission } from "@/modules/notifications";
import { settingsPubSub } from "@/modules/pubSub";
import { inferenceTypes } from "@/modules/settings";
Expand All @@ -25,15 +24,6 @@ export default function AISettingsForm() {
onValuesChange: setSettings,
});

const searchResultsToConsiderSliderMarks = useMemo(
() =>
Array.from({ length: 7 }, (_, index) => ({
value: index,
label: index.toString(),
})),
[],
);

const handleNotificationToggle = async (
event: React.ChangeEvent<HTMLInputElement>,
) => {
Expand Down Expand Up @@ -75,21 +65,6 @@ export default function AISettingsForm() {
description="Show a browser notification when the AI response is ready. Useful for longer queries that take time to process."
/>

<Stack gap="xs" mb="md">
<Text size="sm">Search results to consider</Text>
<Text size="xs" c="dimmed">
Determines the number of search results to consider when
generating AI responses. A higher value may enhance accuracy, but
it will also increase response time.
</Text>
<Slider
{...form.getInputProps("searchResultsToConsider")}
min={0}
max={6}
marks={searchResultsToConsiderSliderMarks}
/>
</Stack>

<Select
{...form.getInputProps("inferenceType")}
label="AI Processing Location"
Expand Down
1 change: 0 additions & 1 deletion client/modules/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ describe("Settings Module", () => {
expect(defaultSettings.showEnableAiResponsePrompt).toBe(true);
expect(defaultSettings.enableAiResponse).toBe(false);
expect(defaultSettings.enableImageSearch).toBe(true);
expect(defaultSettings.searchResultsToConsider).toBe(3);
expect(defaultSettings.searchResultsLimit).toBe(15);
expect(defaultSettings.inferenceType).toBeDefined();
});
Expand Down
1 change: 0 additions & 1 deletion client/modules/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const defaultSettings = {
enableImageSearch: true,
wllamaModelId: VITE_WLLAMA_DEFAULT_MODEL_ID,
cpuThreads: Math.max(1, (navigator.hardwareConcurrency ?? 1) - 2),
searchResultsToConsider: 3,
searchResultsLimit: 15,
systemPrompt: `Answer using the search results below as your primary source, supplemented by your own knowledge when needed. Write your response in the same language as the query.

Expand Down
5 changes: 2 additions & 3 deletions client/modules/textGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
ChatGenerationError,
defaultContextSize,
getFormattedSearchResults,
searchResultsToConsider,
} from "./textGenerationUtilities";
import type {
ChatMessage,
Expand Down Expand Up @@ -403,9 +404,7 @@ async function startTextSearch(query: string) {
results.textResults.length === 0 ? "failed" : "completed",
);
updateTextSearchResults(textResults);
updateLlmTextSearchResults(
textResults.slice(0, getSettings().searchResultsToConsider),
);
updateLlmTextSearchResults(textResults.slice(0, searchResultsToConsider));

updateSearchResults(getCurrentSearchRunId(), {
type: "text",
Expand Down
11 changes: 7 additions & 4 deletions client/modules/textGenerationUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import type { ChatMessage } from "./types";
*/
export const defaultContextSize = 4096;

/**
* Number of top text search results included in the AI context
*/
export const searchResultsToConsider = 6;

/**
* Custom error class for chat generation failures
*/
Expand Down Expand Up @@ -48,10 +53,8 @@ export function getFormattedSearchResults(shouldIncludeUrl: boolean) {
* Waits for search results if they are required before starting response generation
*/
export async function canStartResponding() {
if (getSettings().searchResultsToConsider > 0) {
updateTextGenerationState("awaitingSearchResults");
await getSearchPromise();
}
updateTextGenerationState("awaitingSearchResults");
await getSearchPromise();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions docs/ai-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ Stream response via selected inference type
Update PubSub channels (response, textGenerationState)
```

The AI context includes the top 6 text search results (a fixed value, `searchResultsToConsider` in `client/modules/textGenerationUtilities.ts`), not a user-configurable setting.

### Chat Generation

```
Expand Down Expand Up @@ -336,12 +338,10 @@ Wllama models are sharded (split into chunks):

### For Maximum Quality
- Use OpenAI GPT-4 or Internal API with large model
- Set `searchResultsToConsider: 5-10`
- Adjust temperature: 0.5-0.7 for factual, 0.8-1.0 for creative

### For Cost Efficiency
- Use AI Horde (free) or Browser inference - Wllama (one-time download)
- Set `searchResultsToConsider: 3` (default)
- Limit `inferenceMaxTokens: 2048`

### For Teams/Enterprise
Expand Down
1 change: 0 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Settings are stored in browser localStorage and can be changed via the Settings
| `showEnableAiResponsePrompt` | boolean | `true` | Show prompt to enable AI response on first use |
| `enableImageSearch` | boolean | `true` | Include image results in searches |
| `enableTextSearch` | boolean | `true` | Include text results in searches |
| `searchResultsToConsider` | number | `3` | Number of top search results to include in AI context |
| `searchResultsLimit` | number | `15` | Maximum search results to fetch |
| `systemPrompt` | string | (template) | Custom system prompt template for AI |
| `enterToSubmit` | boolean | `true` | Press Enter to submit query (vs Shift+Enter for new line) |
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ MiniSearch uses a PubSub-based architecture where state flows through independen
- `idle` - No active generation
- `awaitingModelDownloadAllowance` - Waiting for user consent to download a browser model
- `loadingModel` - Downloading or initializing the browser (Wllama) model
- `awaitingSearchResults` - Waiting for search to complete before generating (only when `searchResultsToConsider > 0`)
- `awaitingSearchResults` - Waiting for search to complete before generating
- `preparingToGenerate` - Building the prompt/request just before calling the inference backend (OpenAI-compatible, Internal API, and AI Horde paths)
- `generating` - Streaming response tokens
- `interrupted` - Generation was cancelled by the user
Expand Down