Skip to content

Commit

Permalink
Merge pull request #149 from vespa-engine/revert-148-lesters/rag-in-v…
Browse files Browse the repository at this point in the history
…espa

Revert "Move RAG search to Vespa"
  • Loading branch information
freva authored Jun 24, 2024
2 parents 916db0e + 98a066c commit b28b2a1
Showing 1 changed file with 26 additions and 37 deletions.
63 changes: 26 additions & 37 deletions src/App/libs/provider/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { parseUrlParams, createUrlParams } from 'App/libs/provider/url-params';

export const useSearchContext = create(createStore);
const endpoint = import.meta.env.VITE_ENDPOINT;
const dummyEventSource = Object.freeze({
close: () => {},
addEventListener: () => {},
removeEventListener: () => {},
});

export function SearchContext() {
const location = useLocation();
Expand Down Expand Up @@ -51,52 +56,36 @@ export function SearchContext() {
if (query.length === 0) return;
const filters = namespaces.map((n) => `+namespace:${n}`).join(' ');

let cancelled = false;

// If the user has not consented to the abstract yet, use regular search
if (!abstractConsent) {
const searchUrl = new UrlBuilder(endpoint)
.add('search')
.queryParam('query', query)
.queryParam('filters', filters)
.queryParam('queryProfile', 'llmsearch')
.toString(true);
Get(searchUrl)
.then(
(result) =>
!cancelled && setHits({ hits: result.root.children ?? [] }),
)
.catch((error) => !cancelled && setHits({ error }));
return () => {
cancelled = true;
};
}

// However, if the user has consented, use RAG search
const streamUrl = new UrlBuilder(endpoint)
.add('sse')
.add('stream')
.queryParam('query', query)
.queryParam('filters', filters)
.queryParam('queryProfile', 'ragsearch')
.queryParam('llm.includeHits', 'true')
.queryParam('queryProfile', 'llmsearch')
.toString(true);
const source = new EventSource(streamUrl);
const onToken = (e) => summaryAppend(JSON.parse(e.data).token);
const onHits = (e) => {
if (!cancelled) {
const result = JSON.parse(e.data);
setHits({ hits: result.root.children ?? [] });
}
};
const source = abstractConsent
? new EventSource(streamUrl)
: dummyEventSource;
const onMessage = (e) => summaryAppend(e.data);
const onError = () => summaryComplete() || source.close();
source.addEventListener('token', onToken);
source.addEventListener('hits', onHits);
source.addEventListener('message', onMessage);
source.addEventListener('error', onError);

let cancelled = false;
const searchUrl = new UrlBuilder(endpoint)
.add('search')
.queryParam('query', query)
.queryParam('filters', filters)
.queryParam('queryProfile', 'llmsearch')
.toString(true);
Get(searchUrl)
.then(
(result) => !cancelled && setHits({ hits: result.root.children ?? [] }),
)
.catch((error) => !cancelled && setHits({ error }));
return () => {
cancelled = true;
source.close();
source.removeEventListener('token', onToken);
source.removeEventListener('hits', onHits);
source.removeEventListener('message', onMessage);
source.removeEventListener('error', onError);
};
}, [
Expand Down

0 comments on commit b28b2a1

Please sign in to comment.