How to use embedings in ollama cli? How can it read pdfs?
- User
How to use embedings in ollama cli? How can it read pdfs?
Assistant
Here's a concise guide to using embeddings with Ollama CLI for PDFs:
Basic Setup
- Install Required Python Packages
pip install langchain pypdf ollama chromadbSimple Python Script Example
from langchain.document_loaders import PyPDFLoader from langchain.embeddings import OllamaEmbeddings from langchain.vectorstores import Chroma from langchain.llms import Ollama from langchain.chains import RetrievalQA # Load PDF loader = PyPDFLoader("your_pdf.pdf") pages = loader.load_and_split() # Initialize Ollama embeddings embeddings = OllamaEmbeddings(model="llama2") # or any other model you have # Create vector store db = Chroma.from_documents(pages, embeddings) # Setup QA chain llm = Ollama(model="llama2") qa_chain = RetrievalQA.from_chain_type( llm=llm, chain_type="stuff", retriever=db.as_retriever() ) # Ask questions question = "What is this document about?" answer = qa_chain.run(question) print(answer)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.