SciSharp / LLamaSharp

A C#/.NET library to run LLM (🦙LLaMA/LLaVA) on your local device efficiently.
https://scisharp.github.io/LLamaSharp
MIT License
2.48k stars 332 forks source link

LlamaEmbedder How to use #91

Closed twentytwokhz closed 1 year ago

twentytwokhz commented 1 year ago

How should I use the LlamaEmbedder after I created one? I was not able to find any relevant information or code snippets. Thanks!

martindevans commented 1 year ago
var @params = new ModelParams(modelPath);
var embedder = new LLamaEmbedder(@params);
var result = embedder.GetEmbeddings("Hello");

This seems to work for me. result is filled with a load of numbers which are presumably the embedding vector of "Hello"

twentytwokhz commented 1 year ago

I might not have explained it accurately 🥲 After creating that vector how can I use it within LlamaSharp for an existing model?

martindevans commented 1 year ago

I don't think LLamaSharp itself has anything that will consume embeddings, that's usually down to your own system (e.g. an external vector database). What are you actually trying to do with the embeddings?

twentytwokhz commented 1 year ago

I'm trying to get the embedding from a text extracted from a PDF File. I want to feed it into the llm model for a QA type bot

martindevans commented 1 year ago

Maybe I'm misunderstanding what you're asking, but I don't think you'd feed the embeddings into the LLM. Instead you would retrieve some text (e.g. using a vector database to find knowledge "nearby" the question embedding vector) and then feed that into the context when you ask your question. That's not something LLamaSharp does - it'll do the start (generate embeddings) and the end (run the LLM) but not the middle bit (use the embeddings to retrieve some knowledge).

I know some people have been working on higher level things (e.g. BotSharp and SemanticKernel) which may do more of what you want (I'm not very familiar with those projects, so I'm not sure)

twentytwokhz commented 1 year ago

Thank you for clarifying!

Oceania2018 commented 1 year ago

@twentytwokhz @martindevans Here is the updated docs related to how to adpot the LlamaSharp in a high level bot framework. I'll keep update the docs and let me know if you can run it through according the latest docs.