Llama.cpp for FULL LOCAL Semantic Router
Key Takeaways
This video demonstrates how to use llama.cpp LLM and HuggingFace embedding models for a full local semantic router
Full Transcript
today we're going to take a look at the new features in semantic router that allow us to take everything fully local so we'll be using llama CPP for the dynamic routes and the hugging face encoder for our routing decisions now one thing I really like about this is that using a very small model so we're going to be using mistal 7B we add grammars onto that and using this format we seem to be getting much better results for a gentic decision making than I can get with GPT 3.5 now all of this I'm going to be running from my M1 MacBook Pro so it's not like I have anything crazy here and it it will run pretty quick as we'll see so let's jump straight into it now I'm starting off in the semantic router Library coming over to here and I'm going to download that onto my MC once that has been downloaded we should be able to open it and we'll see this and what I'm going to do is just pip install semantic router so I'm just switching across my terminal here if you if you have the local git repo you can install the most recent version like this but I'm going to go ahead and install it from pipy so semantic router and we want 0.0.6 now coming down to here if you are on Mac you want to use this so that's just to speed things up I'm going to use the Myst 7B instruct model it's quantized so you know we can actually run this pretty easily it's not you don't need much to run this and it runs surprising ly quickly while we are waiting for that to download I'm going to come over to here and I'll just point out the pr where we got this implemented so this one from Bugan from aelio super cool and there's one thing in particular I wanted to point out which is that we use these llm grammars here now the LM grammars they are essentially enforcing a particular structured output from your llm which is a big part of why we can get very good performance from a very small model like mol 7B and it is surprisingly good I'm actually seeing better performance with this and M 7B than I am gbt 3.5 which is I think pretty insane now that has been downloaded so the the my model now we'll come down to initial izing our Dynamic route and you might recognize this from the previous example where we demoed a dynamic route I'm using the exact same one here but we're just going to swap out the openingi encoder and the open LM for a hooking face encoder and the mystal 7B LM exact same definitions here so this is our Dynamic route so the get time route and we also have the static routes here as well so they are also in there I'm going to take all of those routes and can drop that time SCH it there and we just put all of our routes in a list here and we're going to use them soon to initialize our route layer but to initialize our rout layer we do need an encoder so we go ahead and we initialize that we're using the Hing face encoder here which by default is the sentence Transformers or Min LM L6 V2 which is a tiny tiny model so you can also run this on pretty much anything as well now we want to come over to here to begin initializing our mystal 7B model there's a little bit of explanation on what we're actually using here we are going to simplify the way that you initialize a llama CPP model but for now this is how you do it and we will still have this option so the idea is we'll probably make it so that if you don't pass in this llm parameter we will use default parameters I when initializing it but for those of you that you know do want to modify your parameters you will be able to so let's run this I'm going to run it on GPU okay so I have that here and then we can initialize our route layer okay so we have our encoder so the H face encoder our routes that we defined before so two static one Dynamic and we have mro 7B okay cool looks good and now let's ask how's the weather today we see that we hit our static route the chat route now let's ask what is the time in New York right now okay and you can see the the grammar coming through here I'm not I'm not actually sure how to stop those from being logged as I'm sure there must be way but we'll figure that out in a future release we have the time and here in the UK it is 1603 so that is correct what is time in Rome right now so I think they're an hour ahead 1703 is correct then I want to try something a little further out the way this so it's I think this is the question where GPT 3.5 actually struggled with quite a lot which is surprising I would kind of expected to be okay with this but it really struggled so what is the time in Bangkok right now I'm going to run this we get 2304 I don't know what the time is in Bangkok right now 2304 so that is correct and then the time in puket as well so I want to you know somewhere that's not a main city because you look at the time zone here and it has Bangkok in the time zone name someone to try okay pck it and then I'm actually not sure why but this this command here or or this question takes way longer to answer than the others and I I yeah I'm not I'm not 100% sure why that is which is kind of interesting but anyway so we're going to be waiting a little moment for this one but I will say that this question that just G gbt 3.5 answering it I I didn't test this exact question but if it couldn't answer bangcock I feel like it would not have been able to answer for bat cool so we come down here we see Asia Bangkok for the time zone and yeah we get the the same time there now let me just double check that they are in the same time I'm pretty sure they are okay yeah cool so it's all good and then we just downloaded the mro model so if you do want to remove that from your computer you can you just run this command the bottom here and yeah that is everything so we have got a fully local semantic router running now it works with LL CPP and it uses llm grammar to just make the performance of small models pretty good as you can see then alongside that we also have the new hugging face encoders which means that any embedding model that is supported by hunging face we most likely support it unless it does some sort of weird pooling mechanism which most of them don't most of them are pretty straightforward so we yeah we can now use semantic router with a ton more models and we can do all that locally which is pretty exciting so that's it for this video I just wanted to show you this very quickly so I will leave it there I hope this has all been interesting and useful but for now thank you very much for watching and I will see you again in the next one bye
Original Description
Using fully local semantic router for agentic AI with llama.cpp LLM and HuggingFace embedding models.
There are many reasons we might decide to use local LLMs rather than use a third-party service like OpenAI. It could be cost, privacy, compliance, or fear of the OpenAI apocalypse. To help you out, we made Semantic Router fully local with local LLMs available via llama.cpp like Mistral 7B.
Using llama.cpp also enables the use of quantized GGUF models, reducing the memory footprint of deployed models and allowing even 13-billion parameter models to run with hardware acceleration on an Apple M1 Pro chip. We also use LLM grammars to enable high output reliability even from the smallest of models.
In this video, we'll use HuggingFace's MiniLM encoder, and llama.cpp's Mistral-7B-instruct GGUF quantized.
⭐ GitHub Repo:
https://github.com/aurelio-labs/semantic-router/
📌 Code:
https://github.com/aurelio-labs/semantic-router/blob/main/docs/05-local-execution.ipynb
🔥 Semantic Router Course:
https://www.aurelio.ai/course/semantic-router
👋🏼 AI Consulting:
https://aurelio.ai
👾 Discord:
https://discord.gg/c5QtDB9RAP
Twitter: https://twitter.com/jamescalam
LinkedIn: https://www.linkedin.com/in/jamescalam/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from James Briggs · James Briggs · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Stoic Philosophy Text Generation with TensorFlow
James Briggs
How to Build TensorFlow Pipelines with tf.data.Dataset
James Briggs
Every New Feature in Python 3.10.0a2
James Briggs
How-to Build a Transformer for Language Classification in TensorFlow
James Briggs
How-to use the Kaggle API in Python
James Briggs
Language Generation with OpenAI's GPT-2 in Python
James Briggs
Text Summarization with Google AI's T5 in Python
James Briggs
How-to do Sentiment Analysis with Flair in Python
James Briggs
Python Environment Setup for Machine Learning
James Briggs
Sequential Model - TensorFlow Essentials #1
James Briggs
Functional API - TensorFlow Essentials #2
James Briggs
Training Parameters - TensorFlow Essentials #3
James Briggs
Input Data Pipelines - TensorFlow Essentials #4
James Briggs
6 of Python's Newest and Best Features (3.7-3.9)
James Briggs
Novice to Advanced RegEx in Less-than 30 Minutes + Python
James Briggs
Building a PlotLy $GME Chart in Python
James Briggs
How-to Use The Reddit API in Python
James Briggs
How to Build Custom Q&A Transformer Models in Python
James Briggs
How to Build Q&A Models in Python (Transformers)
James Briggs
How-to Decode Outputs From NLP Models (Python)
James Briggs
Identify Stocks on Reddit with SpaCy (NER in Python)
James Briggs
Sentiment Analysis on ANY Length of Text With Transformers (Python)
James Briggs
Unicode Normalization for NLP in Python
James Briggs
The NEW Match-Case Statement in Python 3.10
James Briggs
Multi-Class Language Classification With BERT in TensorFlow
James Briggs
How to Build Python Packages for Pip
James Briggs
How-to Structure a Q&A ML App
James Briggs
How to Index Q&A Data With Haystack and Elasticsearch
James Briggs
Q&A Document Retrieval With DPR
James Briggs
How to Use Type Annotations in Python
James Briggs
Extractive Q&A With Haystack and FastAPI in Python
James Briggs
Sentence Similarity With Sentence-Transformers in Python
James Briggs
Sentence Similarity With Transformers and PyTorch (Python)
James Briggs
NER With Transformers and spaCy (Python)
James Briggs
Training BERT #1 - Masked-Language Modeling (MLM)
James Briggs
Training BERT #2 - Train With Masked-Language Modeling (MLM)
James Briggs
Training BERT #3 - Next Sentence Prediction (NSP)
James Briggs
Training BERT #4 - Train With Next Sentence Prediction (NSP)
James Briggs
FREE 11 Hour NLP Transformers Course (Next 3 Days Only)
James Briggs
New Features in Python 3.10
James Briggs
Training BERT #5 - Training With BertForPretraining
James Briggs
How-to Use HuggingFace's Datasets - Transformers From Scratch #1
James Briggs
Build a Custom Transformer Tokenizer - Transformers From Scratch #2
James Briggs
3 Traditional Methods for Similarity Search (Jaccard, w-shingling, Levenshtein)
James Briggs
3 Vector-based Methods for Similarity Search (TF-IDF, BM25, SBERT)
James Briggs
Building MLM Training Input Pipeline - Transformers From Scratch #3
James Briggs
Training and Testing an Italian BERT - Transformers From Scratch #4
James Briggs
Faiss - Introduction to Similarity Search
James Briggs
Angular App Setup With Material - Stoic Q&A #5
James Briggs
Why are there so many Tokenization methods in HF Transformers?
James Briggs
Choosing Indexes for Similarity Search (Faiss in Python)
James Briggs
Locality Sensitive Hashing (LSH) for Search with Shingling + MinHashing (Python)
James Briggs
How LSH Random Projection works in search (+Python)
James Briggs
IndexLSH for Fast Similarity Search in Faiss
James Briggs
Faiss - Vector Compression with PQ and IVFPQ (in Python)
James Briggs
Product Quantization for Vector Similarity Search (+ Python)
James Briggs
How to Build a Bert WordPiece Tokenizer in Python and HuggingFace
James Briggs
Metadata Filtering for Vector Search + Latest Filter Tech
James Briggs
Build NLP Pipelines with HuggingFace Datasets
James Briggs
Composite Indexes and the Faiss Index Factory
James Briggs
More on: LLM Engineering
View skill →Related Reads
📰
📰
📰
📰
GPT-5.5 Complete Guide in 2026
Dev.to AI
AI Simplified — Why Structured Output Matters More Than a Fluent Answer
Dev.to AI
I ran a 110B LLM on 16GB of RAM. Here's the equation that predicts any model's speed on your machine
Dev.to · Federico Sciuca
A Fidelity-First Workflow for Editing GPT-Generated Text
Dev.to · Bisrat
🎓
Tutor Explanation
DeepCamp AI