Chapter 22
vector search persistent
Notebookllm-zoomcamp-2026-vector10 cells
In [ ]python · cell 1
python
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')Output
Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.
Loading weights: 0%| | 0/103 [00:00<?, ?it/s]
In [3]python · cell 2
python
from sqlitesearch import VectorSearchIndex
vs_index = VectorSearchIndex(
keyword_fields=['course'],
mode='ivf',
db_path='faq_vectors2.db'
)In [7]python · cell 3
python
query = 'I just discovered the course. Can I still join it?'
query_vector = model.encode(query)
results = vs_index.search(
query_vector,
filter_dict={'course': 'llm-zoomcamp'},
num_results=5
)In [8]python · cell 4
python
resultsOutput
[{'id': '74eb249bbf',
'course': 'llm-zoomcamp',
'section': 'General Course-Related Questions',
'question': 'I just discovered the course. Can I still join?',
'answer': 'Yes, but if you want to receive a certificate, you need to submit your project while we’re still accepting submissions.'},
{'id': '69d122f12e',
'course': 'llm-zoomcamp',
'section': 'General Course-Related Questions',
'question': 'Certificate: Can I follow the course in a self-paced mode and get a certificate?',
'answer': 'No, you can only get a certificate if you finish the course with a "live" cohort.\n\nWe don\'t award certificates for the self-paced mode. The reason is you need to peer-review 3 capstone(s) after submitting your project.\n\nYou can only peer-review projects at the time the course is running; after the form is closed and the peer-review list is compiled.'},
{'id': 'bd31146b0e',
'course': 'llm-zoomcamp',
'section': 'General Course-Related Questions',
'question': 'When will the course be offered next?',
'answer': 'Summer 2025.'},
{'id': '977bf7786c',
'course': 'llm-zoomcamp',
'section': 'General Course-Related Questions',
'question': 'Course: I have registered for the LLM Zoomcamp. When can I expect to receive the confirmation email?',
'answer': "You don't need it. You're accepted. You can also just start learning and submitting homework (while the form is open) without registering. It is not checked against any registered list. Registration is just to gauge interest before the start date."},
{'id': '85384a18e5',
'course': 'llm-zoomcamp',
'section': 'Module 1: Introduction to LLMs and RAG',
'question': 'OpenAI: Do I have to subscribe and pay for Open AI API for this course?',
'answer': "No, you don't have to pay for this service in order to complete the course homeworks. You could use some of the free alternatives listed in the course GitHub.\n\n[llm-zoomcamp/01-intro/open-ai-alternatives.md at main · DataTalksClub/llm-zoomcamp (github.com)](https://github.com/DataTalksClub/llm-zoomcamp/blob/main/01-intro/open-ai-alternatives.md)"}]In [9]python · cell 5
python
from rag_helper import RAGBase
class RAGVector(RAGBase):
def __init__(self, embedder, **kwargs):
super().__init__(**kwargs)
self.embedder = embedder
def search(self, query, num_results=5):
query_vector = self.embedder.encode(query)
filter_dict = {'course': self.course}
return self.index.search(
query_vector,
num_results=num_results,
filter_dict=filter_dict
)In [10]python · cell 6
python
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
openai_client = OpenAI()In [11]python · cell 7
python
vector_assistant = RAGVector(
embedder=model,
index=vs_index,
llm_client=openai_client,
)In [12]python · cell 8
python
vector_assistant.rag('the program has already begun, can I still sign up?')Output
'Yes, you can still sign up. You can join even after the course has started, but if you want to receive a certificate, make sure you submit your project while submissions are still open.'
In [13]python · cell 9
python
vector_assistant.rag('whats queen gambit?')Output
"I don't know."
In [ ]python · cell 10
python
