⚡️ use reranker for docs context provider
This commit is contained in:
parent
ec6ca8a156
commit
2be3fb12e8
4 changed files with 43 additions and 7 deletions
|
|
@ -65,6 +65,13 @@ const CODE_BLOCK_END = "```";
|
|||
const multilineStops = [DOUBLE_NEWLINE, WINDOWS_DOUBLE_NEWLINE];
|
||||
const commonStops = [SRC_DIRECTORY, PYTHON_ENCODING, CODE_BLOCK_END];
|
||||
|
||||
// Errors that can be expected on occasion even during normal functioning should not be shown.
|
||||
// Not worth disrupting the user to tell them that a single autocomplete request didn't go through
|
||||
const ERRORS_TO_IGNORE = [
|
||||
// From Ollama
|
||||
"unexpected server status: 1",
|
||||
];
|
||||
|
||||
function formatExternalSnippet(
|
||||
filepath: string,
|
||||
snippet: string,
|
||||
|
|
@ -284,8 +291,16 @@ export async function getTabCompletion(
|
|||
lineGenerator = streamWithNewLines(lineGenerator);
|
||||
|
||||
const finalGenerator = stopAtSimilarLine(lineGenerator, lineBelowCursor);
|
||||
for await (const update of finalGenerator) {
|
||||
completion += update;
|
||||
|
||||
try {
|
||||
for await (const update of finalGenerator) {
|
||||
completion += update;
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (ERRORS_TO_IGNORE.some((err) => e.includes(err))) {
|
||||
return undefined;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (cancelled) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import configs from "../../indexing/docs/preIndexedDocs";
|
|||
import TransformersJsEmbeddingsProvider from "../../indexing/embeddings/TransformersJsEmbeddingsProvider";
|
||||
|
||||
class DocsContextProvider extends BaseContextProvider {
|
||||
static DEFAULT_N_RETRIEVE = 30;
|
||||
static DEFAULT_N_FINAL = 15;
|
||||
static description: ContextProviderDescription = {
|
||||
title: "docs",
|
||||
displayTitle: "Docs",
|
||||
|
|
@ -26,13 +28,32 @@ class DocsContextProvider extends BaseContextProvider {
|
|||
const embeddingsProvider = new TransformersJsEmbeddingsProvider();
|
||||
const [vector] = await embeddingsProvider.embed([extras.fullInput]);
|
||||
|
||||
const chunks = await retrieveDocs(
|
||||
let chunks = await retrieveDocs(
|
||||
query,
|
||||
vector,
|
||||
this.options?.nRetrieve || 15,
|
||||
this.options?.nRetrieve ?? DocsContextProvider.DEFAULT_N_RETRIEVE,
|
||||
embeddingsProvider.id,
|
||||
);
|
||||
|
||||
if (extras.reranker) {
|
||||
try {
|
||||
const scores = await extras.reranker.rerank(query, chunks);
|
||||
chunks.sort(
|
||||
(a, b) => scores[chunks.indexOf(b)] - scores[chunks.indexOf(a)],
|
||||
);
|
||||
chunks = chunks.splice(
|
||||
0,
|
||||
this.options?.nFinal ?? DocsContextProvider.DEFAULT_N_FINAL,
|
||||
);
|
||||
} catch (e) {
|
||||
console.warn(`Failed to rerank docs results: ${e}`);
|
||||
chunks = chunks.splice(
|
||||
0,
|
||||
this.options?.nFinal ?? DocsContextProvider.DEFAULT_N_FINAL,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
...chunks
|
||||
.map((chunk) => ({
|
||||
|
|
|
|||
|
|
@ -247,10 +247,10 @@ const Layout = () => {
|
|||
{indexingProgress >= 1 && // Would take up too much space together with indexing progress
|
||||
defaultModel?.provider === "free-trial" &&
|
||||
(location.pathname === "/settings" ||
|
||||
parseInt(localStorage.getItem("ftc") || "0") >= 125) && (
|
||||
parseInt(localStorage.getItem("ftc") || "0") >= 50) && (
|
||||
<ProgressBar
|
||||
completed={parseInt(localStorage.getItem("ftc") || "0")}
|
||||
total={250}
|
||||
total={150}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ function GUI(props: GUIProps) {
|
|||
const u = parseInt(ftc);
|
||||
localStorage.setItem("ftc", (u + 1).toString());
|
||||
|
||||
if (u >= 250) {
|
||||
if (u >= 150) {
|
||||
dispatch(setShowDialog(true));
|
||||
dispatch(setDialogMessage(<FTCDialog />));
|
||||
posthog?.capture("ftc_reached");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue