tryAGI/LangChain

System.MissingMethodException when using LLMSharpEmbeddings

Closed this issue · 1 comments

Describe the bug

I'm trying to use LLMSharpEmbeddings to use a SqlLite db to setup a RAG:

 var modelPath = @"D:\LLMModels\Models\thespis-13b-v0.5.Q2_K.gguf";
 //Also tested with Meta-Llama-3.1-8B-Instruct-Q6_K

 var vectorDatabase = new SqLiteVectorDatabase(dataSource: @"D:\LLMModels\DBs\hp.db");
 var embeddingModel = LLamaSharpEmbeddings.FromPath(modelPath);

 var fileAddress = @"D:\LLMModels\RAGResources\Books\Harry-Potter-and-the-Philosophers-Stone.pdf";
 var dataSource = DataSource.FromPath(fileAddress);


 var vectorCollection = await vectorDatabase.AddDocumentsFromAsync<PdfPigPdfLoader>(
     embeddingModel, // Used to convert text to embeddings
     dimensions: 5120, // Not sure about this param!
     dataSource: dataSource,
     collectionName: "harrypotter", // Can be omitted, use if you want to have multiple collections
     textSplitter: null,
     behavior: AddDocumentsToDatabaseBehavior.OverwriteExistingCollection);


 const string question = "What is Harry's Address?";
 var similarDocuments = await vectorCollection.GetSimilarDocuments(embeddingModel, question, amount: 5);

 Console.WriteLine($"Similar Doc Count: {similarDocuments.Count}");

However at this line:

var embeddingModel = LLamaSharpEmbeddings.FromPath(modelPath);

the following exception is thrown:
System.MissingMethodException HResult=0x80131513 Message=Method not found: '!!0 Microsoft.Extensions.AI.IEmbeddingGenerator2.GetService(System.Object)'.
Source=LangChain.Providers.LLamaSharp
StackTrace:
at LangChain.Providers.LLamaSharp.LLamaSharpEmbeddings..ctor(LLamaSharpConfiguration configuration)
`

Steps to reproduce the bug

  1. Create a console app and add required packages
  2. Copy and paste the given code to the main method
  3. Adjust the address of the model to your local address
  4. Run the project

Expected behavior

No response

Screenshots

image

NuGet package version

Additional context

I also tried this:

 var embeddingModel = new LLamaSharpEmbeddings(new LLamaSharpConfiguration
 {
     PathToModelFile = modelPath,
     EmbeddingMode = true,
 });

Dear admin, please remove this. I should have asked this in the LLamaSharp project