[GH-ISSUE #9903] RAG confusion. #68541

Closed
opened 2026-05-04 14:23:14 -05:00 by GiteaMirror · 16 comments
Owner

Originally created by @JG-Adams on GitHub (Mar 20, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/9903

The API documentation for embedding only told half of the picture. You embed it. Now what? How do you actually use RAG? Where does the embedding go? I'm real confused as to why there's little information on it because it's such an important feature. I even had to figure out that this is in fact a RAG.

Originally created by @JG-Adams on GitHub (Mar 20, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/9903 The API documentation for embedding only told half of the picture. You embed it. Now what? How do you actually use RAG? Where does the embedding go? I'm real confused as to why there's little information on it because it's such an important feature. I even had to figure out that this is in fact a RAG.
GiteaMirror added the question label 2026-05-04 14:23:15 -05:00
Author
Owner

@rick-github commented on GitHub (Mar 20, 2025):

ollama is not a RAG, it can be used as a component in a RAG system by creating embeddings and/or response synthesis.

See here for a description of how RAG works, and here for integrations that use ollama in a RAG system.

<!-- gh-comment-id:2739719996 --> @rick-github commented on GitHub (Mar 20, 2025): ollama is not a RAG, it can be used as a component in a RAG system by creating embeddings and/or response synthesis. See [here](https://en.wikipedia.org/wiki/Retrieval-augmented_generation) for a description of how RAG works, and [here](https://github.com/ollama/ollama?tab=readme-ov-file#community-integrations) for integrations that use ollama in a RAG system.
Author
Owner

@muhammadismailkhan0009 commented on GitHub (Mar 20, 2025):

RAG is used as input to LLM. so, you will have implement RAG system separately, and add the RAG data into prompts that you are feeding to LLM. the implementation depends upon the programming language and framework you'll be using.

<!-- gh-comment-id:2739957833 --> @muhammadismailkhan0009 commented on GitHub (Mar 20, 2025): RAG is used as input to LLM. so, you will have implement RAG system separately, and add the RAG data into prompts that you are feeding to LLM. the implementation depends upon the programming language and framework you'll be using.
Author
Owner

@JG-Adams commented on GitHub (Mar 20, 2025):

Ok thanks. But what I'm asking is not how RAG work or whether Ollama is RAG (I never said it was) but how embedding is used. I'm looking to do RAG.

"RAG is used as input to LLM. so, you will have implement RAG system separately, and add the RAG data into prompts that you are feeding to LLM. the implementation depends upon the programming language and framework you'll be using."

From what I can tell you provide input through the embedding function? That make this a way to do RAG. I'll figure out my own implementation which is C++. (If embedding is not for RAG then I'm curious. What is it for?)

My questions still goes unanswered. "You embed it. Now what?" "Where does the embedding go? " in other word, how is it used afterward?

Guys please just answer the question and maybe provide some clarity in the documents so others wouldn't have to be so confused.

<!-- gh-comment-id:2741285362 --> @JG-Adams commented on GitHub (Mar 20, 2025): Ok thanks. But what I'm asking is not how RAG work or whether Ollama is RAG (I never said it was) but how embedding is used. I'm looking to do RAG. "RAG is used as input to LLM. so, you will have implement RAG system separately, and add the RAG data into prompts that you are feeding to LLM. the implementation depends upon the programming language and framework you'll be using." From what I can tell you provide input through the embedding function? That make this a way to do RAG. I'll figure out my own implementation which is C++. (If embedding is not for RAG then I'm curious. What is it for?) My questions still goes unanswered. "You embed it. Now what?" "Where does the embedding go? " in other word, how is it used afterward? Guys please just answer the question and maybe provide some clarity in the documents so others wouldn't have to be so confused.
Author
Owner

@rick-github commented on GitHub (Mar 20, 2025):

The embedding goes in a vector database. Details in the link I provided.

<!-- gh-comment-id:2741291099 --> @rick-github commented on GitHub (Mar 20, 2025): The embedding goes in a vector database. Details in the link I provided.
Author
Owner

@JG-Adams commented on GitHub (Mar 20, 2025):

Nice link. But I asked for clarification. And that is not an answer to my question. Look at the API Document dude. It showed that you embed this, "Why is the sky blue?" Does it make any sense to embed a question for retrieval? Like what the heck?!

https://github.com/ollama/ollama/blob/main/docs/api.md#generate-embeddings

Here's what it says:

Generate Embeddings
POST /api/embed
Generate embeddings from a model

Parameters
model: name of model to generate embeddings from
input: text or list of text to generate embeddings for
Advanced parameters:

truncate: truncates the end of each input to fit within context length. Returns error if false and context length is exceeded. Defaults to true
options: additional model parameters listed in the documentation for the Modelfile such as temperature
keep_alive: controls how long the model will stay loaded into memory following the request (default: 5m)
Examples
Request
curl http://localhost:11434/api/embed -d '{
"model": "all-minilm",
"input": "Why is the sky blue?"
}'
Response
{
"model": "all-minilm",
"embeddings": [[
0.010071029, -0.0017594862, 0.05007221, 0.04692972, 0.054916814,
0.008599704, 0.105441414, -0.025878139, 0.12958129, 0.031952348
]],
"total_duration": 14143917,
"load_duration": 1019500,
"prompt_eval_count": 8
}

So there's the response from this. A vector database. Now I ask again. How do you use? Like how do I get the AI to respond with this data?

<!-- gh-comment-id:2741371054 --> @JG-Adams commented on GitHub (Mar 20, 2025): Nice link. But I asked for clarification. And that is not an answer to my question. Look at the API Document dude. It showed that you embed this, "Why is the sky blue?" Does it make any sense to embed a question for retrieval? Like what the heck?! [https://github.com/ollama/ollama/blob/main/docs/api.md#generate-embeddings](url) Here's what it says: Generate Embeddings POST /api/embed Generate embeddings from a model Parameters model: name of model to generate embeddings from input: text or list of text to generate embeddings for Advanced parameters: truncate: truncates the end of each input to fit within context length. Returns error if false and context length is exceeded. Defaults to true options: additional model parameters listed in the documentation for the [Modelfile](https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values) such as temperature keep_alive: controls how long the model will stay loaded into memory following the request (default: 5m) Examples Request curl http://localhost:11434/api/embed -d '{ "model": "all-minilm", "input": "Why is the sky blue?" }' Response { "model": "all-minilm", "embeddings": [[ 0.010071029, -0.0017594862, 0.05007221, 0.04692972, 0.054916814, 0.008599704, 0.105441414, -0.025878139, 0.12958129, 0.031952348 ]], "total_duration": 14143917, "load_duration": 1019500, "prompt_eval_count": 8 } So there's the response from this. A vector database. Now I ask again. How do you use? Like how do I get the AI to respond with this data?
Author
Owner

@rick-github commented on GitHub (Mar 20, 2025):

Does it make any sense to embed a question for retrieval?

Why not? The purpose of the RAG system might be to find questions that are similar. So you get the embedding for "Why is the sky blue?" and put it in the vector database. You add other questions like "Why is the grass green?","Why is the sunset orange?" and "Why do dogs have tails?". Then somebody has a query about questions pertaining to colours of natural phenomena. You can query the vector database for vectors that are similar to the vector for "Why is the sky blue?" and then rank the results on the cosine similarity of the returned vectors, and you will get blue sky, green grass, orange sunset but not dog tails.

So there's the response from this. A vector database. Now I ask again. How do you use? Like how do I get the AI to respond with this data?

The AI doesn't respond to this data. You put the vectors in a database, see "Indexing" in the provided link. Then a question is asked. The question is turned into a vector and used to query the vector database, see "Retrieval". The database query returns a list of vectors that match the query vector. Those vectors are ranked and the associated documents scored. Then the original question and the documents are passed to the model ("Augmentation") and the response from the model ("Generation") is returned to the client as a response to the question.

<!-- gh-comment-id:2741409751 --> @rick-github commented on GitHub (Mar 20, 2025): > Does it make any sense to embed a question for retrieval? Why not? The purpose of the RAG system might be to find questions that are similar. So you get the embedding for "Why is the sky blue?" and put it in the vector database. You add other questions like "Why is the grass green?","Why is the sunset orange?" and "Why do dogs have tails?". Then somebody has a query about questions pertaining to colours of natural phenomena. You can query the vector database for vectors that are similar to the vector for "Why is the sky blue?" and then rank the results on the cosine similarity of the returned vectors, and you will get blue sky, green grass, orange sunset but not dog tails. > So there's the response from this. A vector database. Now I ask again. How do you use? Like how do I get the AI to respond with this data? The AI doesn't respond to this data. You put the vectors in a database, see "Indexing" in the provided link. Then a question is asked. The question is turned into a vector and used to query the vector database, see "Retrieval". The database query returns a list of vectors that match the query vector. Those vectors are ranked and the associated documents scored. Then the original question and the documents are passed to the model ("Augmentation") and the response from the model ("Generation") is returned to the client as a response to the question.
Author
Owner

@JG-Adams commented on GitHub (Mar 20, 2025):

Does it make any sense to embed a question for retrieval?

Why not? The purpose of the RAG system might be to find questions that are similar. So you get the embedding for "Why is the sky blue?" and put it in the vector database. You add other questions like "Why is the grass green?","Why is the sunset orange?" and "Why do dogs have tails?". Then somebody has a query about questions pertaining to colours of natural phenomena. You can query the vector database for vectors that are similar to the vector for "Why is the sky blue?" and then rank the results on the cosine similarity of the returned vectors, and you will get blue sky, green grass, orange sunset but not dog tails.

So there's the response from this. A vector database. Now I ask again. How do you use? Like how do I get the AI to respond with this data?

The AI doesn't respond to this data. You put the vectors in a database, see "Indexing" in the provided link. Then a question is asked. The question is turned into a vector and used to query the vector database, see "Retrieval". The database query returns a list of vectors that match the query vector. Those vectors are ranked and the associated documents scored. Then the original question and the documents are passed to the model ("Augmentation") and the response from the model ("Generation") is returned to the client as a response to the question.

HOW NOT TO UNDERSTAND PEOPLE'S QUESTION.

You said, "The AI doesn't respond to this data." Holy cow dude. I said "with" the data. Not "to" it. What I'm looking for turned out to be query. How to query it. Now why not you say? Is it helpful to look for similarity to a question? The whole point of RAG is to retrieve the information that could be helpful to answer a user's question. Like for example we now know Saturn to have the most moon. But AI by itself may only know Jupiter to have the most moon. Which is an outdated piece of information. Why do I gotta spell everything out for you? I'm not here to talk about how RAG work. Learn to read.
Seriously now. What are you even doing???

<!-- gh-comment-id:2741435924 --> @JG-Adams commented on GitHub (Mar 20, 2025): > > Does it make any sense to embed a question for retrieval? > > Why not? The purpose of the RAG system might be to find questions that are similar. So you get the embedding for "Why is the sky blue?" and put it in the vector database. You add other questions like "Why is the grass green?","Why is the sunset orange?" and "Why do dogs have tails?". Then somebody has a query about questions pertaining to colours of natural phenomena. You can query the vector database for vectors that are similar to the vector for "Why is the sky blue?" and then rank the results on the cosine similarity of the returned vectors, and you will get blue sky, green grass, orange sunset but not dog tails. > > > So there's the response from this. A vector database. Now I ask again. How do you use? Like how do I get the AI to respond with this data? > > The AI doesn't respond to this data. You put the vectors in a database, see "Indexing" in the provided link. Then a question is asked. The question is turned into a vector and used to query the vector database, see "Retrieval". The database query returns a list of vectors that match the query vector. Those vectors are ranked and the associated documents scored. Then the original question and the documents are passed to the model ("Augmentation") and the response from the model ("Generation") is returned to the client as a response to the question. HOW NOT TO UNDERSTAND PEOPLE'S QUESTION. You said, "The AI doesn't respond to this data." Holy cow dude. I said "with" the data. Not "to" it. What I'm looking for turned out to be query. How to query it. Now why not you say? Is it helpful to look for similarity to a question? The whole point of RAG is to retrieve the information that could be helpful to answer a user's question. Like for example we now know Saturn to have the most moon. But AI by itself may only know Jupiter to have the most moon. Which is an outdated piece of information. Why do I gotta spell everything out for you? I'm not here to talk about how RAG work. Learn to read. Seriously now. What are you even doing???
Author
Owner

@rick-github commented on GitHub (Mar 20, 2025):

My understanding is you want to use a RAG system to answer questions.

The whole point of RAG is to retrieve the information that could be helpful to answer a user's question.

So this is how to use RAG to answer a question about moons:

The information about the moons of Saturn ("Saturn has 274 moons") is processed into an embedding (/api/embed). The embedding is inserted in a vector database ("Indexing") with a pointer to the document from which embedding was generated. Then a user has a question about Saturnian moons ("How many moons does Saturn have?"). The question is converted to an embedding and used to query the vector database ("Retrieval"). The database returns a list of vectors and associated documents that are close matches to the query vector. One of those vectors corresponds to the document that contains "Saturn has 274 moons". Now the RAG system passes the original question ("How many moons does Saturn have?") and the retrieved documents ("Saturn has 274 moons" and others that had a close vector match but might not be as relevant as the first one) to the LLM ("Augmentation"). The response from the model ("Generation") is returned to the user as a response to the question.

If this doesn't help with your original question of How do you actually use RAG then please feel free to ask follow up questions.

<!-- gh-comment-id:2741490667 --> @rick-github commented on GitHub (Mar 20, 2025): My understanding is you want to use a RAG system to answer questions. > The whole point of RAG is to retrieve the information that could be helpful to answer a user's question. So this is how to use RAG to answer a question about moons: The information about the moons of Saturn ("Saturn has 274 moons") is processed into an embedding (`/api/embed`). The embedding is inserted in a vector database ("Indexing") with a pointer to the document from which embedding was generated. Then a user has a question about Saturnian moons ("How many moons does Saturn have?"). The question is converted to an embedding and used to query the vector database ("Retrieval"). The database returns a list of vectors and associated documents that are close matches to the query vector. One of those vectors corresponds to the document that contains "Saturn has 274 moons". Now the RAG system passes the original question ("How many moons does Saturn have?") and the retrieved documents ("Saturn has 274 moons" and others that had a close vector match but might not be as relevant as the first one) to the LLM ("Augmentation"). The response from the model ("Generation") is returned to the user as a response to the question. If this doesn't help with your original question of `How do you actually use RAG` then please feel free to ask follow up questions.
Author
Owner

@JG-Adams commented on GitHub (Mar 20, 2025):

I want to be clear that I didn't come to stackoverflow to be given a link. I'm here to talk about some missing info in our API document.
So forget about the wikipedia page. Look at the API document for embedding and tell me if that is all the steps you take to do what you just described.

You have explained how it work. Now I want to know how to use it. There's a difference. Like putting it into practical use in CODE.

As I try to understand, here's what I get from your last response:

  1. Embed "Saturn has 274 moons" (It gets inserted into a vector database and automatically point to it?)
  2. You ask a question. "How many moons does Saturn have?" (Assuming it's using the newly embedded info)
  3. It goes through the vector database for similarity and answer with it.

Is that it? I gave it a go and it did not work. So clearly something is missing. Like how to use the embedded data for our user prompted question?

<!-- gh-comment-id:2741565891 --> @JG-Adams commented on GitHub (Mar 20, 2025): I want to be clear that I didn't come to stackoverflow to be given a link. I'm here to talk about some missing info in our API document. So forget about the wikipedia page. Look at the API document for embedding and tell me if that is all the steps you take to do what you just described. You have explained how it work. Now I want to know how to use it. There's a difference. Like putting it into practical use in CODE. As I try to understand, here's what I get from your last response: 1. Embed "Saturn has 274 moons" (It gets inserted into a vector database and automatically point to it?) 2. You ask a question. "How many moons does Saturn have?" (Assuming it's using the newly embedded info) 3. It goes through the vector database for similarity and answer with it. Is that it? I gave it a go and it did not work. So clearly something is missing. Like how to use the embedded data for our user prompted question?
Author
Owner

@rick-github commented on GitHub (Mar 20, 2025):

I gave it a go and it did not work

If you show the code then perhaps we could debug it.

<!-- gh-comment-id:2741578258 --> @rick-github commented on GitHub (Mar 20, 2025): > I gave it a go and it did not work If you show the code then perhaps we could debug it.
Author
Owner

@JG-Adams commented on GitHub (Mar 20, 2025):

Thanks for your patience.
I'm using Ollama-hpp. for C++.
Here is the site: https://github.com/jmont-dev/ollama-hpp

I didn't expect this to work at all.

#include "ollama.hpp"
#include "json.hpp"
int main()
{
std::string Model = "llama3.2:latest";
ollama::show_requests(true);
ollama::show_replies(true);
std::cout << ollama::generate_embeddings(Model, "Saturn has 274 moons.") << std::endl;
std::cout << ollama::generate(Model, "How many moons does Saturn has?") << std::endl;
return 0;
}

<!-- gh-comment-id:2741594882 --> @JG-Adams commented on GitHub (Mar 20, 2025): Thanks for your patience. I'm using Ollama-hpp. for C++. Here is the site: [https://github.com/jmont-dev/ollama-hpp](url) I didn't expect this to work at all. #include "ollama.hpp" #include "json.hpp" int main() { std::string Model = "llama3.2:latest"; ollama::show_requests(true); ollama::show_replies(true); std::cout << ollama::generate_embeddings(Model, "Saturn has 274 moons.") << std::endl; std::cout << ollama::generate(Model, "How many moons does Saturn has?") << std::endl; return 0; }
Author
Owner

@rick-github commented on GitHub (Mar 20, 2025):

OK, as I said at the start, ollama is not a RAG system, it is a component. You need other components to make a RAG system, one of which is a vector database. I know you don't want a link but I feel there's a knowledge gap here that could be helped by reading through an example: https://huggingface.co/blog/ngxson/make-your-own-rag. This is in python but the fundamentals apply: embeddings, storing vectors in a (very simple) database, lookups and generation.

<!-- gh-comment-id:2741616121 --> @rick-github commented on GitHub (Mar 20, 2025): OK, as I said at the start, ollama is not a RAG system, it is a component. You need other components to make a RAG system, one of which is a vector database. I know you don't want a link but I feel there's a knowledge gap here that could be helped by reading through an example: https://huggingface.co/blog/ngxson/make-your-own-rag. This is in python but the fundamentals apply: embeddings, storing vectors in a (very simple) database, lookups and generation.
Author
Owner

@JG-Adams commented on GitHub (Mar 20, 2025):

Thank you for your help. That is vital piece of information. I managed to convert it to C++ and it worked. Fantastic. They don't seem to have a C++ solution out there do they?

As a reward for your assistance. I think I will make a github site to share my codes after I polish it a bit.

As for all the confusion I got regarding the API document. I still think it could use some refinement. There is no indication that embedding is the first step to RAG and it needs an implementation for it. Honestly I'm not sure how it should be exactly.

<!-- gh-comment-id:2741749388 --> @JG-Adams commented on GitHub (Mar 20, 2025): Thank you for your help. That is vital piece of information. I managed to convert it to C++ and it worked. Fantastic. They don't seem to have a C++ solution out there do they? As a reward for your assistance. I think I will make a github site to share my codes after I polish it a bit. As for all the confusion I got regarding the API document. I still think it could use some refinement. There is no indication that embedding is the first step to RAG and it needs an implementation for it. Honestly I'm not sure how it should be exactly.
Author
Owner

@rick-github commented on GitHub (Mar 20, 2025):

They don't seem to have a C++ solution out there do they?

There likely is but I haven't touched C++ in about 10 years so I don't have any recommendations.

There is no indication that embedding is the first step to RAG

It's not really the province of ollama to create tutorials on how to implement external systems, whether it's RAG or chatbots or vision analysis systems. That's where examples like the huggingface link or information resources like Wikipedia come in.

<!-- gh-comment-id:2741763145 --> @rick-github commented on GitHub (Mar 20, 2025): > They don't seem to have a C++ solution out there do they? There likely is but I haven't touched C++ in about 10 years so I don't have any recommendations. > There is no indication that embedding is the first step to RAG It's not really the province of ollama to create tutorials on how to implement external systems, whether it's RAG or chatbots or vision analysis systems. That's where examples like the huggingface link or information resources like Wikipedia come in.
Author
Owner

@JG-Adams commented on GitHub (Mar 20, 2025):

I agree. But what I'm really saying is. The fact that it is only a piece of the puzzle to having RAG is actually good to know. Cause it's not saying anything at all about what it's good for. The word "RAG" isn't even mentioned at all in the doc.

Looking it up I couldn't find any such implementation. Not even perplexity is aware of it. I'm sure people will appreciate this.
Since the code was free I assume the converted one should also be free. What license should I use? MIT?

<!-- gh-comment-id:2741802741 --> @JG-Adams commented on GitHub (Mar 20, 2025): I agree. But what I'm really saying is. The fact that it is only a piece of the puzzle to having RAG is actually good to know. Cause it's not saying anything at all about what it's good for. The word "RAG" isn't even mentioned at all in the doc. Looking it up I couldn't find any such implementation. Not even perplexity is aware of it. I'm sure people will appreciate this. Since the code was free I assume the converted one should also be free. What license should I use? MIT?
Author
Owner

@JG-Adams commented on GitHub (Mar 21, 2025):

Ok I did it.
https://github.com/JG-Adams/RAGcpp
Hope this is good.

Also thank you very much for your help!

<!-- gh-comment-id:2742519948 --> @JG-Adams commented on GitHub (Mar 21, 2025): Ok I did it. https://github.com/JG-Adams/RAGcpp Hope this is good. Also thank you very much for your help!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#68541