Skip to content

Commit 4d58063

Browse files
committed
refactor(api): switch public ask-ai config to Typesense conversational search
1 parent 6485ee2 commit 4d58063

5 files changed

Lines changed: 36 additions & 132 deletions

File tree

packages/docsearch-react/src/DocSearch.tsx

Lines changed: 20 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
DocumentSchema,
2222
SearchParams as TypesenseSearchParams,
2323
} from 'typesense/lib/Typesense/Documents';
24-
import type { MultiSearchRequestSchema } from "typesense/lib/Typesense/Types"
24+
import type { MultiSearchRequestSchema } from 'typesense/lib/Typesense/Types';
2525

2626
import { DocSearchButton } from './DocSearchButton';
2727
import { DocSearchModal } from './DocSearchModal';
@@ -33,6 +33,7 @@ import type {
3333
} from './types';
3434

3535
import type { ButtonTranslations, ModalTranslations } from '.';
36+
import type { TypesenseAskAiSearchParameters } from './types/AskiAi';
3637

3738
export type { DocSearchRef } from '@docsearch/core';
3839

@@ -54,85 +55,33 @@ export type DocSearchTransformClient = {
5455
transporter: Pick<LiteClient['transporter'], 'algoliaAgent'>;
5556
};
5657

57-
// Define the specific search parameters allowed for Ask AI
58-
export type AskAiSearchParameters = {
59-
facetFilters?: string[];
60-
filters?: string;
61-
attributesToRetrieve?: string[];
62-
restrictSearchableAttributes?: string[];
63-
distinct?: boolean | number | string;
64-
};
65-
66-
export type AgentStudioSearchParameters = Record<
67-
string,
68-
Omit<AskAiSearchParameters, 'facetFilters'>
69-
>;
70-
7158
export type DocSearchAskAi = {
7259
/**
73-
* The index name to use for the ask AI feature. Your assistant will search this index for relevant documents.
74-
* If not provided, the index name will be used.
60+
* Typesense conversational model id.
7561
*/
76-
indexName?: string;
62+
conversationModelId: string;
7763
/**
78-
* The API key to use for the ask AI feature. Your assistant will use this API key to search the index.
79-
* If not provided, the API key will be used.
64+
* Collection to query for conversational retrieval.
65+
* Defaults to `typesenseCollectionName`.
8066
*/
81-
apiKey?: string;
67+
collection?: string;
8268
/**
83-
* The app ID to use for the ask AI feature. Your assistant will use this app ID to search the index.
84-
* If not provided, the app ID will be used.
69+
* Query field to use for conversational retrieval.
70+
*
71+
* @default 'embedding'
8572
*/
86-
appId?: string;
73+
queryBy?: string;
8774
/**
88-
* The assistant ID to use for the ask AI feature.
75+
* Fields excluded from the conversational payload.
76+
*
77+
* @default 'embedding'
8978
*/
90-
assistantId: string;
79+
excludeFields?: string;
9180
/**
92-
* Enables displaying suggested questions on Ask AI's new conversation screen.
93-
*
94-
* @default false
81+
* Additional Typesense search parameters for the conversational retrieval request.
9582
*/
96-
suggestedQuestions?: boolean;
97-
// HACK: This is a hack for testing staging, remove before releasing
98-
useStagingEnv?: boolean;
99-
} & (
100-
| {
101-
/**
102-
* **Experimental:** Whether to use Agent Studio as the chat backend.
103-
*
104-
* This is an experimental feature and its API may change without notice in future releases.
105-
* Use with caution in production environments.
106-
*
107-
* @default false
108-
*/
109-
agentStudio?: never;
110-
/**
111-
* The search parameters to use for the ask AI feature.
112-
*
113-
* **NOTE**: If using `agentStudio = true`, the `searchParameters` object is
114-
* keyed by the index name.
115-
*/
116-
searchParameters?: AskAiSearchParameters;
117-
}
118-
| {
119-
agentStudio: false;
120-
searchParameters?: AskAiSearchParameters;
121-
}
122-
| {
123-
agentStudio: true;
124-
/**
125-
* The search parameters to use for the ask AI feature.
126-
* Keyed by the index name.
127-
*
128-
* @example
129-
* {
130-
* "INDEX_NAME": { distinct: false }
131-
* }
132-
*/
133-
searchParameters?: AgentStudioSearchParameters;
134-
}
135-
);
83+
searchParameters?: TypesenseAskAiSearchParameters;
84+
};
13685

13786
export interface DocSearchIndex {
13887
name: string;
@@ -162,9 +111,9 @@ export interface DocSearchProps {
162111
*/
163112
indices?: Array<DocSearchIndex | string>;
164113
/**
165-
* Configuration or assistant id to enable ask ai mode. Pass a string assistant id or a full config object.
114+
* Configuration to enable Typesense conversational search.
166115
*/
167-
askAi?: DocSearchAskAi | string;
116+
askAi?: DocSearchAskAi;
168117
/**
169118
* Intercept Ask AI requests (e.g. Submitting a prompt or selecting a suggested question).
170119
*

packages/docsearch-react/src/Footer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ export function Footer({ translations = {}, isAskAiActive = false }: FooterProps
4848
backToSearchText = 'Back to search',
4949
closeKeyAriaLabel = 'Escape key',
5050
poweredByText = 'Powered by',
51-
searchByText = 'Search by',
51+
searchByText,
5252
} = translations;
5353

5454
return (
5555
<>
5656
<div className="DocSearch-Logo">
57-
<TypesenseLogo translations={{ searchByText: searchByText || poweredByText }} />
57+
<TypesenseLogo translations={{ searchByText: searchByText ?? poweredByText }} />
5858
</div>
5959
<ul className="DocSearch-Commands">
6060
<li>

packages/docsearch-react/src/Sidepanel.tsx

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,29 @@
11
import { DocSearch, useDocSearch } from '@docsearch/core';
22
import type { DocSearchCallbacks, DocSearchRef, DocSearchTheme, SidepanelShortcuts } from '@docsearch/core';
3+
import type { ConfigurationOptions as TypesenseConfigurationOptions } from 'typesense/lib/Typesense/Configuration';
34
import type { JSX } from 'react';
45
import React from 'react';
56
import { createPortal } from 'react-dom';
67

7-
import type { AgentStudioSearchParameters, AskAiSearchParameters } from './DocSearch';
8+
import type { DocSearchAskAi } from './DocSearch';
89
import type { SidepanelButtonProps, SidepanelProps as SidepanelPanelProps } from './Sidepanel/index';
910
import { SidepanelButton, Sidepanel } from './Sidepanel/index';
1011

1112
export type { DocSearchRef, DocSearchCallbacks } from '@docsearch/core';
1213

13-
export type SidepanelSearchParameters =
14-
| {
15-
/**
16-
* **Experimental:** Whether to use Agent Studio as the chat backend.
17-
*
18-
* This is an experimental feature and its API may change without notice in future releases.
19-
* Use with caution in production environments.
20-
*
21-
* @default false
22-
*/
23-
agentStudio?: never;
24-
/**
25-
* The search parameters to use for the ask AI feature.
26-
*
27-
* **NOTE**: If using `agentStudio = true`, the `searchParameters` object is
28-
* keyed by the index name.
29-
*/
30-
searchParameters?: AskAiSearchParameters;
31-
}
32-
| {
33-
agentStudio: false;
34-
searchParameters?: AskAiSearchParameters;
35-
}
36-
| {
37-
agentStudio: true;
38-
/**
39-
* The search parameters to use for the ask AI feature.
40-
* Keyed by the index name.
41-
*
42-
* @example
43-
* {
44-
* "INDEX_NAME": { distinct: false }
45-
* }
46-
*/
47-
searchParameters?: AgentStudioSearchParameters;
48-
};
49-
5014
export type DocSearchSidepanelProps = DocSearchCallbacks & {
5115
/**
52-
* The assistant ID to use for the ask AI feature.
53-
*/
54-
assistantId: string;
55-
/**
56-
* Public api key with search permissions for the index.
16+
* Typesense server configuration used by sidepanel search.
5717
*/
58-
apiKey: string;
18+
typesenseServerConfig: TypesenseConfigurationOptions;
5919
/**
60-
* Algolia application id used by the search client.
20+
* Typesense collection name used for keyword search.
6121
*/
62-
appId: string;
22+
typesenseCollectionName: string;
6323
/**
64-
* The index name to use for the ask AI feature. Your assistant will search this index for relevant documents.
24+
* Typesense conversational search configuration.
6525
*/
66-
indexName: string;
26+
askAi: DocSearchAskAi;
6727
/**
6828
* Configuration for keyboard shortcuts. Allows enabling/disabling specific shortcuts.
6929
*
@@ -86,10 +46,8 @@ export type DocSearchSidepanelProps = DocSearchCallbacks & {
8646
panel?: Omit<SidepanelPanelProps, 'keyboardShortcuts'>;
8747
};
8848

89-
type SidepanelProps = DocSearchSidepanelProps & SidepanelSearchParameters;
90-
9149
function DocSearchSidepanelComponent(
92-
{ keyboardShortcuts, theme, onReady, onOpen, onClose, onSidepanelOpen, onSidepanelClose, ...props }: SidepanelProps,
50+
{ keyboardShortcuts, theme, onReady, onOpen, onClose, onSidepanelOpen, onSidepanelClose, ...props }: DocSearchSidepanelProps,
9351
ref: React.ForwardedRef<DocSearchRef>,
9452
): JSX.Element {
9553
return (
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import type { DocSearchTransformClient } from '..';
2-
import { version } from '../version';
3-
4-
export const setSidepanelSearchClient = (client: DocSearchTransformClient): DocSearchTransformClient => {
5-
if (/docsearch-sidepanel.js \(.*\)/.test(client.transporter.algoliaAgent.value) === false) {
6-
client.addAlgoliaAgent('docsearch-sidepanel', version);
7-
}
1+
import type { TypesenseDocsearchTransformClient } from '../DocSearch';
82

3+
export const setSidepanelSearchClient = (
4+
client: TypesenseDocsearchTransformClient,
5+
): TypesenseDocsearchTransformClient => {
96
return client;
107
};

packages/docsearch-react/src/TypesenseLogo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { type JSX } from 'react';
22

3-
type TypesenseLogoTranslations = Partial<{
3+
export type TypesenseLogoTranslations = Partial<{
44
searchByText: string;
55
}>;
66

0 commit comments

Comments
 (0)