repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { Embeddings } from "@langchain/core/embeddings"; |
| #2 | import { Embedder } from "./base"; |
| #3 | import { EmbeddingConfig } from "../types"; |
| #4 | |
| #5 | export class LangchainEmbedder implements Embedder { |
| #6 | private embedderInstance: Embeddings; |
| #7 | private batchSize?: number; // Some LC embedders have batch size |
| #8 | |
| #9 | constructor(config: EmbeddingConfig) { |
| #10 | // Check if config.model is provided and is an object (the instance) |
| #11 | if (!config.model || typeof config.model !== "object") { |
| #12 | throw new Error( |
| #13 | "Langchain embedder provider requires an initialized Langchain Embeddings instance passed via the 'model' field in the embedder config.", |
| #14 | ); |
| #15 | } |
| #16 | // Basic check for embedding methods |
| #17 | if ( |
| #18 | typeof (config.model as any).embedQuery !== "function" || |
| #19 | typeof (config.model as any).embedDocuments !== "function" |
| #20 | ) { |
| #21 | throw new Error( |
| #22 | "Provided Langchain 'instance' in the 'model' field does not appear to be a valid Langchain Embeddings instance (missing embedQuery or embedDocuments method).", |
| #23 | ); |
| #24 | } |
| #25 | this.embedderInstance = config.model as Embeddings; |
| #26 | // Store batch size if the instance has it (optional) |
| #27 | this.batchSize = (this.embedderInstance as any).batchSize; |
| #28 | } |
| #29 | |
| #30 | async embed(text: string): Promise<number[]> { |
| #31 | try { |
| #32 | // Use embedQuery for single text embedding |
| #33 | return await this.embedderInstance.embedQuery(text); |
| #34 | } catch (error) { |
| #35 | console.error("Error embedding text with Langchain Embedder:", error); |
| #36 | throw error; |
| #37 | } |
| #38 | } |
| #39 | |
| #40 | async embedBatch(texts: string[]): Promise<number[][]> { |
| #41 | try { |
| #42 | // Use embedDocuments for batch embedding |
| #43 | // Langchain's embedDocuments handles batching internally if needed/supported |
| #44 | return await this.embedderInstance.embedDocuments(texts); |
| #45 | } catch (error) { |
| #46 | console.error("Error embedding batch with Langchain Embedder:", error); |
| #47 | throw error; |
| #48 | } |
| #49 | } |
| #50 | } |
| #51 |