ollama create opt-rag -f ./ragmodelfile main[?] via 💠 default │
│ main.tf │gathering model components │
│ * ragmodelf│Error: invalid int value [99 # Ensure all layers are offloaded to the GPU]
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
It looks like there was an issue with the syntax in your RAGModelfile. The PARAMETER lines should not include comments or extra spaces. Let's correct the RAGModelfile and ensure it follows the proper format.
Here is the corrected RAGModelfile:
Dockerfile
# Use the Q5_K_M version we downloaded for balance
FROM llama3:8b-instruct-q5_k_m
# Set system parameters for performance
PARAMETER num_gpu 99
PARAMETER num_ctx 8192
# Set a default system prompt for RAG tasks
SYSTEM """
You are a helpful assistant that answers questions based strictly on the provided context.
If the answer is not in the context, state that you cannot find the information.
"""
Make sure to save this file as RAGModelfile in your working directory.
Steps to Create the Optimized Model
Create the Optimized Model in Ollama:
bash
ollama create opt-rag -f ./RAGModelfile
Test Your New Optimized Model:
bash
ollama run opt-rag
Integrating the LLM into Your RAG Application
Now that you have a highly optimized LLM running locally via Ollama, you need to connect your RAG application to it.
Example using LangChain (Python)
If you are building your RAG system in Python using LangChain, integration is straightforward:
python
from langchain_community.llms import Ollama
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
# Initialize the connection to your optimized local model
llm = Ollama(model="opt-rag")
# Example RAG prompt structure
prompt = ChatPromptTemplate.from_template(
"Answer the question based only on the following context:\n"
"<context>{context}</context>\n\n"
"Question: {input}"
)
# --- In a real RAG app, your VectorDB provides the context ---
retrieved_context = "The M4 chip features up to a 10-core GPU based on the new graphics architecture introduced in M3."
user_question = "How many GPU cores does the M4 chip have?"
# Create the chain
chain = prompt | llm | StrOutputParser()
# Run the chain
response = chain.invoke({"input": user_question, "context": retrieved_context})
print(response)
Example using LlamaIndex (Python)
LlamaIndex integration is equally simple:
python
from llama_index.llms.ollama import Ollama
from llama_index.core import Settings
# Configure LlamaIndex to use your local model globally
Settings.llm = Ollama(model="opt-rag", request_timeout=30.0)
# ... Proceed with your standard LlamaIndex VectorStore setup ...
Summary of Your Optimized Local Setup
By following these steps, you have achieved the fastest and most reliable setup for your 24GB MacBook:
Hardware: MacBook M-series 24GB (Utilizing Metal GPU)
Inference Server: Ollama (using llama.cpp)
Model: Llama 3 8B Instruct (or Mistral 7B)
Format: GGUF Q5_K_M (Balance of speed/accuracy)
Optimization: Full GPU offloading (num_gpu 99) and maximum context (num_ctx 8192).
Access: Via REST API at http://localhost:11434.
This setup should provide you with a highly efficient and reliable local LLM deployment for your RAG application.