diff --git a/libs/langchain-community/src/embeddings/ollama.ts b/libs/langchain-community/src/embeddings/ollama.ts index c1e1f36ec9a9..845af4669f8a 100644 --- a/libs/langchain-community/src/embeddings/ollama.ts +++ b/libs/langchain-community/src/embeddings/ollama.ts @@ -113,6 +113,9 @@ export class OllamaEmbeddings extends Embeddings { const snakeCasedOption = mapping[key as keyof CamelCasedRequestOptions]; if (snakeCasedOption) { snakeCasedOptions[snakeCasedOption] = value; + } else { + // Just pass unknown options through + snakeCasedOptions[key] = value; } } return snakeCasedOptions; diff --git a/libs/langchain-ollama/src/embeddings.ts b/libs/langchain-ollama/src/embeddings.ts index 5e878322a6d9..f330bb8c9580 100644 --- a/libs/langchain-ollama/src/embeddings.ts +++ b/libs/langchain-ollama/src/embeddings.ts @@ -42,7 +42,7 @@ interface OllamaEmbeddingsParams extends EmbeddingsParams { * https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values * for details of the available parameters. */ - requestOptions?: OllamaCamelCaseOptions; + requestOptions?: OllamaCamelCaseOptions & Partial; } export class OllamaEmbeddings extends Embeddings { @@ -121,6 +121,9 @@ export class OllamaEmbeddings extends Embeddings { const snakeCasedOption = mapping[key as keyof OllamaCamelCaseOptions]; if (snakeCasedOption) { snakeCasedOptions[snakeCasedOption as keyof OllamaOptions] = value; + } else { + // Just pass unknown options through + snakeCasedOptions[key as keyof OllamaOptions] = value; } } return snakeCasedOptions; diff --git a/libs/langchain-ollama/src/tests/embeddings.test.ts b/libs/langchain-ollama/src/tests/embeddings.test.ts new file mode 100644 index 000000000000..68c872090424 --- /dev/null +++ b/libs/langchain-ollama/src/tests/embeddings.test.ts @@ -0,0 +1,15 @@ +import { test, expect } from "@jest/globals"; +import { OllamaEmbeddings } from "../embeddings.js"; + +test("Test OllamaEmbeddings allows passthrough of request options", async () => { + const embeddings = new OllamaEmbeddings({ + requestOptions: { + num_ctx: 1234, + numPredict: 4321, + }, + }); + expect(embeddings.requestOptions).toEqual({ + num_ctx: 1234, + num_predict: 4321, + }); +});