Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Method not found: 'System.Threading.Tasks.Task`1<Ollama.GenerateEmbeddingResponse> Ollama.OllamaApiClient.GenerateEmbeddingAsync( #338

Closed
mzeesam opened this issue Jun 11, 2024 · 6 comments
Labels
bug Something isn't working dependencies Pull requests that update a dependency file

Comments

@mzeesam
Copy link

mzeesam commented Jun 11, 2024

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

  1. 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
  2. Installed all nuget packages
  3. Run

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Additional context

No response

@mzeesam mzeesam added the bug Something isn't working label Jun 11, 2024
@HavenDV HavenDV added the dependencies Pull requests that update a dependency file label Jun 11, 2024
@HavenDV
Copy link
Contributor

HavenDV commented Jun 11, 2024

Possibly related to recent changes in the Ollama client, I'll let you know when it's fixed

@mzeesam
Copy link
Author

mzeesam commented Jun 11, 2024

Alright, Thank you. Which versions of libraries/Ollama client can I use in the meantime?

HavenDV added a commit that referenced this issue Jun 11, 2024
@HavenDV
Copy link
Contributor

HavenDV commented Jun 11, 2024

I updated Ollama SDK dependency to latest, new version of LangChain should be available in 5-10 minutes.

@mzeesam
Copy link
Author

mzeesam commented Jun 11, 2024

Thank you sir. Well noted.

However, i am now getting error 404 as shown below:
image

Ollama is running well on localhost.
Or Should I open a different issue?

Thanks.

HavenDV added a commit that referenced this issue Jun 11, 2024
@HavenDV
Copy link
Contributor

HavenDV commented Jun 11, 2024

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

@mzeesam
Copy link
Author

mzeesam commented Jun 11, 2024

Awesome!!... Thanks a lot. The embeddings are created successfully.

@mzeesam mzeesam closed this as completed Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

2 participants