Skip to content

Instantly share code, notes, and snippets.

@fsndzomga
Last active February 1, 2024 00:18
Show Gist options
  • Save fsndzomga/31c0d012ba7d06e6fea2788eaac26d31 to your computer and use it in GitHub Desktop.
Save fsndzomga/31c0d012ba7d06e6fea2788eaac26d31 to your computer and use it in GitHub Desktop.
from ragatouille import RAGPretrainedModel
from ragatouille.utils import get_wikipedia_page
topics = ["Barack_Obama", "Nelson_Mandela", "king"]
RAG = RAGPretrainedModel.from_pretrained("colbert-ir/colbertv2.0")
my_documents = []
# get documents for each topic
for topic in topics:
my_documents.append(get_wikipedia_page(topic))
# create index
index_path = RAG.index(
index_name="leaders",
collection=my_documents,
document_ids=topics,
max_document_length=180,
split_documents=True
)
query = "Who was president of the united states of america in 2010 ?"
#retrieve relevant chunks from index
results = RAG.search(query, k=3)
print(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment