Implementation of Code Using Ollama with Google Colab and create a local local pipeline in the use of Deepseek-R1 1.5b with Ollama, Langchain, FAIS, and Chromadb of Q & An

In this lesson, we will completely develop a complete generation returns using the seams in Google Colab. First, we will look at how we can set Ollama and use models by Colab. Integrating a major Deepseek-R1 1 1.5B model used Ollama, Langchain orchester, and Chronadb Vector Store allows users to ask us real-time information released on the PDFs. With a combination of a local language model Reasoning and restoration of true information from PDF documents, the pipe shows another powerful, confidential form, and inexpensive.
!pip install colab-xterm
%load_ext colabxterm
We use Colob-Xterm extension to enable fatal access directly to the Colob area. By installing it with!
XTERM Magic Command is used after uploading a contact extinguing to introduce the Terminal Networking window Interface. This allows users to issue shell instructions in real time, such as regular terminal, making it especially useful for the LLAMA, or repair of worksheets without leaving a writing book.
Here, we put Ollama using curl | sh.
Then, we start Ollama using Ollama Singana.
Finally, we download Deepseek-R1: 1.5B with local Ollama that can be used to build a rag pipe.
!pip install langchain langchain-community sentence-transformers chromadb faiss-cpu
Setting the main parts of the RAG pipe, including Langchain libraries, including Langchain, Langchain-Community, Transformers, ChransAdb, and FAISS-CPU. These enabled these packages to process documents, embedded, vector maintenance, and returning the work required to create an effective and functional program of the RAG.
from langchain_community.document_loaders import PyPDFLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import Chroma
from langchain_community.embeddings import HuggingFaceEmbeddings
from langchain_community.llms import Ollama
from langchain.chains import RetrievalQA
from google.colab import files
import os
from langchain_core.prompts import ChatPromptTemplate
from langchain_ollama.llms import OllamaLLM
We import Smlary-Community Modules and Langchain-Ollama to manage PDF load, text separation, text division, vector integration, and the llm integration with the Ollama. It includes the use of the Colab file and quick images, which enables them to move seamlessly from the documentation to ask the response to the position managed.
print("Please upload your PDF file...")
uploaded = files.upload()
file_path = list(uploaded.keys())[0]
print(f"File '{file_path}' successfully uploaded.")
if not file_path.lower().endswith('.pdf'):
print("Warning: Uploaded file is not a PDF. This may cause issues.")
Allowing users to add resources to their information, quickly loading the PDF using Google.colab.files.upload (). Verifying the uploaded file type and provides feedback, to ensure that only PDFs are processed to embed and return.
!pip install pypdf
import pypdf
loader = PyPDFLoader(file_path)
documents = loader.load()
print(f"Successfully loaded {len(documents)} pages from PDF")
To remove content from the downloaded PDF, we enter a PYPDF library and use Pydfloader from Langchain to load the document. This process changes each PDF page into a format system, enables fine functions such as the separation of the text and output.
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=1000,
chunk_overlap=200
)
chunks = text_splitter.split_documents(documents)
print(f"Split documents into {len(chunks)} chunks")
The loaded PDF is divided into controlled chunks using recsursuseckerctitter, per chunk to 1000 characters and over 200 characters. This confirms the context of the context best for all chunks, promoting compliance with restored roles in response to the question.
embeddings = HuggingFaceEmbeddings(
model_name="all-MiniLM-L6-v2",
model_kwargs={'device': 'cpu'}
)
persist_directory = "./chroma_db"
vectorstore = Chroma.from_documents(
documents=chunks,
embedding=embeddings,
persist_directory=persist_directory
)
vectorstore.persist()
print(f"Vector store created and persisted to {persist_directory}")
Chunks documents are embedded using Minilm-L6-V2 model from sentence transformers, running to CPU to enable semantic search. This embedding stored in a persistent chromadb vector store, allowing effective returns based on startup at all times.
llm = OllamaLLM(model="deepseek-r1:1.5b")
retriever = vectorstore.as_retriever(
search_type="similarity",
search_kwargs={"k": 3}
)
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=retriever,
return_source_documents=True
)
print("RAG pipeline created successfully!")
The RAG pipe is finalized by connecting the Depseek-R1 local model (with Ollamallm) for the BROMA restored. Using Langchain's Retrivalqa Langchain Langchain strategy “Stuff”, the model returns the top 3 chunks for the question and produces contexts.
def query_rag(question):
result = qa_chain({"query": question})
print("nQuestion:", question)
print("nAnswer:", result["result"])
print("nSources:")
for i, doc in enumerate(result["source_documents"]):
print(f"Source {i+1}:n{doc.page_content[:200]}...n")
return result
question = "What is the main topic of this document?"
result = query_rag(question)
To test the RAG pipe, the questionnaire is taking the user's question, returns the correct context using retrieved, and produces feedback using the llM. It also shows high source documents, which provides the clarity and tracking of the model response.
In conclusion, the lesson includes Ollama, the ability to return Chromadb, the skills of the orchestistration skills in Langchain, and Deepseek-R1 consultation skills in Ollama. Showed to build a non-surviving but rag that works well in Google Colab's free tier. The solution makes users able to ask questions based on the new content from the downloaded documents, with aligned local llm reply. This project provides for the fundamental, customized construction basis, and confidentiality – AI exclusive expenses or compromise costs.
Here is the Colab Notebook. Also, don't forget to follow Sane and join ours Telegraph station including LinkedIn Grtopic. Don't forget to join ours 85k + ml subreddit.
🔥 [Register Now] The Minicon Virtual Conference at an open Source AI: Free Registration + 3 3 Certificate Reference (April 12, 9 pm 12 pm) + workshop [Sponsored]

Asphazzaq is a Markteach Media Inc. According to a View Business and Developer, Asifi is committed to integrating a good social intelligence. His latest attempt is launched by the launch of the chemistrylife plan for an intelligence, MarktechPost, a devastating intimate practice of a machine learning and deep learning issues that are clearly and easily understood. The platform is adhering to more than two million moon visits, indicating its popularity between the audience.
