Error: Method not found: 'System.Threading.Tasks.Task`1<Ollama.GenerateEmbeddingResponse> Ollama.OllamaApiClient.GenerateEmbeddingAsync(
Closed this issue · 6 comments
Describe the bug
I get the below error:
Method not found: 'System.Threading.Tasks.Task`1<Ollama.GenerateEmbeddingResponse> Ollama.OllamaApiClient.GenerateEmbeddingAsync(Ollama.GenerateEmbeddingRequest, System.Threading.CancellationToken)'.
When executing the following lines:
var vectorCollection = await vectorDatabase.AddDocumentsFromAsync(
embeddingModel, // Used to convert text to embeddings
dimensions: 384, // Should be 1536 for TextEmbeddingV3SmallModel
//dimensions: 384, //for all-MiniLM- 384 dimensions
dataSource: DataSource.FromUrl("https://canonburyprimaryschool.co.uk/wp-content/uploads/2016/01/Joanne-K.-Rowling-Harry-Potter-Book-1-Harry-Potter-and-the-Philosophers-Stone-EnglishOnlineClub.com_.pdf"),
collectionName: "harrypotter", // Can be omitted, use if you want to have multiple collections
textSplitter: null,
behavior: AddDocumentsToDatabaseBehavior.JustReturnCollectionIfCollectionIsAlreadyExists);
OR
var similarDocuments = await vectorCollection.GetSimilarDocuments(embeddingModel, question, amount: 5);
I am using version 0.14.1-dev60 in all the nuget packages.
I installed Ollama on my PC and running on the default port: 11434
Below is the entire code:
using LangChain.Databases.Sqlite;
using LangChain.DocumentLoaders;
using LangChain.Providers.Ollama;
using LangChain.Extensions;
using Ollama;
using LangChain.Splitters.Text;
var provider = new OllamaProvider(options: new RequestOptions
{
Stop = ["\n"],
Temperature = 0.0f,
});
var embeddingModel = new OllamaEmbeddingModel(provider, id: "all-minilm");
//var embeddingModel = new OllamaEmbeddingModel(provider, id: "nomic-embed-text");
//var embeddingModel = new OllamaEmbeddingModel(provider, id: "mxbai-embed-large")
var llm = new OllamaChatModel(provider, id: "llama3");
Console.WriteLine($"Setting up vector DB...");
var vectorDatabase = new SqLiteVectorDatabase(dataSource: "vectors.db");
Console.WriteLine($"Loading, Chunking and Indexing data ...");
//Error here below:
var vectorCollection = await vectorDatabase.AddDocumentsFromAsync<PdfPigPdfLoader>(
embeddingModel, // Used to convert text to embeddings
dimensions: 384, // Should be 1536 for TextEmbeddingV3SmallModel
//dimensions: 384, //for all-MiniLM- 384 dimensions
dataSource: DataSource.FromUrl("https://canonburyprimaryschool.co.uk/wp-content/uploads/2016/01/Joanne-K.-Rowling-Harry-Potter-Book-1-Harry-Potter-and-the-Philosophers-Stone-EnglishOnlineClub.com_.pdf"),
collectionName: "harrypotter", // Can be omitted, use if you want to have multiple collections
textSplitter: null,
behavior: AddDocumentsToDatabaseBehavior.JustReturnCollectionIfCollectionIsAlreadyExists);
Console.WriteLine($"Data loading done.");
const string question = "What is Harry's Address?";
Console.WriteLine($"Question: {question}");
var similarDocuments = await vectorCollection.GetSimilarDocuments(embeddingModel, question, amount: 5); //Error here...
// Use similar documents and LLM to answer the question
var answer = await llm.GenerateAsync(
$"""
Use the following pieces of context to answer the question at the end.
If the answer is not in context then just say that you don't know, don't try to make up an answer.
Keep the answer as short as possible.
{similarDocuments.AsString()}
Question: {question}
Helpful Answer:
""").ConfigureAwait(false);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"LLM answer: {answer}");
Console.ForegroundColor = ConsoleColor.White;
//optionally write out the vectordb similar documents
Console.WriteLine("Similar Documents:");
foreach (var document in similarDocuments)
{
Console.WriteLine(document);
}
Steps to reproduce the bug
- Copy the code as expalined in article: https://medium.com/@johnkane24/a-completely-local-rag-net-langchain-sqlite-and-ollama-with-no-api-keys-required-d36c53652f00
- Installed all nuget packages
- Run
Expected behavior
No response
Screenshots
No response
NuGet package version
No response
Additional context
No response
Possibly related to recent changes in the Ollama client, I'll let you know when it's fixed
Alright, Thank you. Which versions of libraries/Ollama client can I use in the meantime?
I updated Ollama SDK dependency to latest, new version of LangChain should be available in 5-10 minutes.
I think it's because default url was changed. You can set custom url in OllamaProvider ctor("http://localhost:11434/api") or just wait for new NuGet
Awesome!!... Thanks a lot. The embeddings are created successfully.