Haystack AI to Create RAG Pipeline

parmarjatin4911@gmail.com - Jan 28 - - Dev Community

Liquid syntax error: Variable '{{

Haystack AI to Create RAG Pipeline

pip install haystack-ai datasets ollama-haystack gradio

ollama run mistral

Importing required libraries

from datasets import load_dataset
from haystack import Document
from haystack.document_stores import InMemoryDocumentStore
from haystack.components.retrievers import InMemoryBM25Retriever
from haystack.components.builders import PromptBuilder
from ollama_haystack import OllamaGenerator
from haystack.pipeline import Pipeline

Load dataset and create documents

dataset = load_dataset("bilgeyucel/seven-wonders", split="train")
docs = [Document(content=doc["content"], meta=doc["meta"]) for doc in dataset]

Initialize document store and write documents

document_store = InMemoryDocumentStore()
document_store.write_documents(docs)

Initialize retriever

retriever = InMemoryBM25Retriever(document_store)

Define prompt template

template = """
Given the following information, answer the question.

Context:
{% for document in documents %}' was not properly terminated with regexp: /\}\}/

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player