-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs: add docs and schema for "OS" provider (#1536) * ignore .env * ✨ use and cache imports for autocomplete (#1456) * ✨ use and cache imports for autocomplete * fix tsc * add voyage rerank-1 * import Handlebars * feat: update onboarding w/ embeddings model (#1570) * chore(gui): remove unused pages * feat: add embeddings step * feat: update styles * feat: copy button updates * fix: correct pull command for embed model * fix: remove commented code * fix: remove commented code * feat: simplify copy btn props * chore: rename onboarding selection event * feat: add provider config * fix: undo msg name * remove dead code * fix: invalid mode check * fix: remove testing logic * fix: fullscreen gui retains context when hidden, fixed fullscreen focusing (#1582) * small UI tweaks * media query * feat: add best experience onboarding * small fixes * feat: add free trial card to onboarding (#1600) * feat: add free trial card to onboarding * add import * chore: add telemetry for full screen toggle (#1618) * rerank-lite-1 * basic tests for VS Code extension * chore: onboarding metrics (#1626) * fix: pageview tracking * feat: add onboarding telemetry * create single `onboardingStatus` type * improved var naming * remove console logs * fix double adding of context providers * fix cross-platform build validation * Update troubleshooting.md (#1637) * add back skip onboarding button * fix free trial embeddings error * Nate/indexing fixes (#1642) * fix pausing of indexing * don't send empty array to openai embeddings * catch embeddings errors without stopping entire indexing process * update version * changelog * Update troubleshooting.md (#1646) * chore: reduce vscode extension bundle size (#1647) * feat: make disabled state a tooltip (#1653) * add content-type header to ollama /api/show req * support legacy OpenAI formatted servers * Tests for indexing + follow all .gitignore syntax (#1661) * cleaner indexing progress updates messages * chunking tests * first round of testing for walkDir in .ts * few more tests * swap fs with ide * clean up dead code * replace traverseDirectory * fix listFolders * smoother indexing updates for chunking * ide pathSetp * absolute paths test * fix path sep error with abs paths on windows * clean up tests * feat: Client Certificate Options Support (#1658) * feat: support client certificate authentication options * docs: support client certificate authentication options * chore: update package.json * docs: move clientCertificate to it's own example * update config_schema.json with client cert options * Add support for the HuggingFace Text Embeddings Inference server (#1657) Co-authored-by: Rob Leidle <[email protected]> * update package.json version --------- Co-authored-by: Patrick Erichsen <[email protected]> Co-authored-by: Jonah Wagner <[email protected]> Co-authored-by: 华丽 <[email protected]> Co-authored-by: Ten <[email protected]> Co-authored-by: Rob Leidle <[email protected]> Co-authored-by: Rob Leidle <[email protected]>
- Loading branch information
1 parent
d69b830
commit 882a79d
Showing
48 changed files
with
1,094 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
core/indexing/embeddings/HuggingFaceTEIEmbeddingsProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import fetch, { Response } from "node-fetch"; | ||
import { EmbedOptions, FetchFunction } from "../.."; | ||
import { withExponentialBackoff } from "../../util/withExponentialBackoff"; | ||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider"; | ||
|
||
class HuggingFaceTEIEmbeddingsProvider extends BaseEmbeddingsProvider { | ||
private maxBatchSize = 32; | ||
|
||
static defaultOptions: Partial<EmbedOptions> | undefined = { | ||
apiBase: "http://localhost:8080", | ||
model: "tei", | ||
}; | ||
|
||
constructor(options: EmbedOptions, fetch: FetchFunction) { | ||
super(options, fetch); | ||
// without this extra slash the last portion of the path will be dropped from the URL when using the node.js URL constructor | ||
if (!this.options.apiBase?.endsWith("/")) { | ||
this.options.apiBase += "/"; | ||
} | ||
this.doInfoRequest().then(response => { | ||
this.options.model = response.model_id; | ||
this.maxBatchSize = response.max_client_batch_size; | ||
}); | ||
} | ||
|
||
async embed(chunks: string[]) { | ||
const promises = []; | ||
for (let i = 0; i < chunks.length; i += this.maxBatchSize) { | ||
promises.push(this.doEmbedRequest(chunks.slice(i, i + this.maxBatchSize))); | ||
} | ||
const results = await Promise.all(promises); | ||
return results.flat(); | ||
} | ||
|
||
async doEmbedRequest(batch: string[]): Promise<number[][]> { | ||
const resp = await withExponentialBackoff<Response>(() => | ||
this.fetch(new URL("embed", this.options.apiBase), { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
inputs: batch | ||
}), | ||
headers: { | ||
"Content-Type": "application/json", | ||
} | ||
}), | ||
); | ||
if (!resp.ok) { | ||
const text = await resp.text(); | ||
const embedError = JSON.parse(text) as TEIEmbedErrorResponse; | ||
if (!embedError.error_type || !embedError.error) { | ||
throw new Error(text); | ||
} | ||
throw new TEIEmbedError(embedError); | ||
} | ||
return (await resp.json()) as number[][]; | ||
} | ||
|
||
async doInfoRequest(): Promise<TEIInfoResponse> { | ||
const resp = await withExponentialBackoff<Response>(() => | ||
this.fetch(new URL("info", this.options.apiBase), { | ||
method: "GET", | ||
}), | ||
); | ||
if (!resp.ok) { | ||
throw new Error(await resp.text()); | ||
} | ||
return (await resp.json()) as TEIInfoResponse; | ||
} | ||
} | ||
|
||
class TEIEmbedError extends Error { | ||
constructor(teiResponse: TEIEmbedErrorResponse) { | ||
super(JSON.stringify(teiResponse)); | ||
} | ||
} | ||
|
||
type TEIEmbedErrorResponse = { | ||
error: string | ||
error_type: string | ||
} | ||
|
||
type TEIInfoResponse = { | ||
model_id: string; | ||
model_sha: string; | ||
model_dtype: string; | ||
model_type: { | ||
embedding: { | ||
pooling: string; | ||
} | ||
}; | ||
max_concurrent_requests: number; | ||
max_input_length: number; | ||
max_batch_tokens: number; | ||
max_batch_requests: number; | ||
max_client_batch_size: number; | ||
auto_truncate: boolean; | ||
tokenization_workers: number; | ||
version: string; | ||
sha: string; | ||
docker_label: string; | ||
}; | ||
|
||
export default HuggingFaceTEIEmbeddingsProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.