Closed Rafael-Julio-2242 closed 1 month ago
Hey, @Rafael-Julio-2242! I'm here to help you with your bug reports, answer your questions, and guide you on how to contribute. Let's solve this issue together!
The newer version of the "OllamaEmbeddings" class from "@langchain/ollama" returns a 404 error because the base URL might be incorrectly set or the endpoint might not exist on the server. The deprecated version from "@langchain/community/embeddings/ollama" works fine because it defaults to "http://localhost:11434" and includes a fallback to "http://127.0.0.1:11434" for Node 18 compatibility [1][2].
Here is the relevant code snippet from the deprecated version that handles the base URL:
let formattedBaseUrl = baseUrl;
if (formattedBaseUrl.startsWith("http://localhost:")) {
// Node 18 has issues with resolving "localhost"
// See https://github.com/node-fetch/node-fetch/issues/1624
formattedBaseUrl = formattedBaseUrl.replace(
"http://localhost:",
"http://127.0.0.1:"
);
}
This ensures that the base URL is correctly formatted, which might be missing or different in the newer version, leading to the 404 error.
Additionally, the newer version includes a migration warning and re-exports everything from the deprecated version, as shown in the following code snippet:
import { logVersion010MigrationWarning } from "../util/entrypoint_deprecation.js";
/* #__PURE__ */ logVersion010MigrationWarning({
oldEntrypointName: "embeddings/ollama",
});
export * from "@langchain/community/embeddings/ollama";
This indicates that the newer version is essentially a wrapper around the deprecated version, but the migration warning or other changes might be causing the 404 error.
Moreover, the newer version of the Ollama class in the "@langchain/ollama" package might not be correctly setting the base URL or other parameters. The constructor in the deprecated version ensures that the base URL is correctly formatted and defaults to "http://localhost:11434":
constructor(fields: OllamaInput & BaseLLMParams) {
super(fields);
this.model = fields.model ?? this.model;
this.baseUrl = fields.baseUrl?.endsWith("/")
? fields.baseUrl.slice(0, -1)
: fields.baseUrl ?? this.baseUrl;
this.keepAlive = fields.keepAlive ?? this.keepAlive;
// other initializations
}
If the newer version does not include similar logic, it could lead to incorrect base URLs and subsequent 404 errors [3].
To continue talking to Dosu, mention @dosu.
Apologies for missing this, this should now be present!
I still have this exact same issue with 0.1.0.
@chaostracker what version of ollama
do you have installed? You can check via:
ollama -v
I have version 0.3.11
installed, and it's working properly.
It was ollama version 0.2.1. I upgraded to 0.3.11 and now it works as expected, so thanks.
Checked other resources
Example Code
I was testing the embeddings for a future project that i need to create, and i have found out that the newer version of the class "OllamaEmbeddings" don't quite work.
The following code:
This Returns an Not Found error, it tries to connect to the Ollama API but it says it don't find.
The error:
But when i use axios or the older version, everthing works just fine.
Same code, but using the older version (the code that works Ok):
The test that i have made with "axios" works, and it ends up being a simple test:
Error Message and Stack Trace (if applicable)
No response
Description
It says in the docs and in the code that the version of "@langchain/community/embeddings/ollama" is deprecated, but that version is working and the other version is not actually working.
System Info
node version v22.6.0 npm version 10.8.2 Mac
Package.json file: