Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
RAGatouille metadata support (#893)
Browse files Browse the repository at this point in the history
* Updated RAGatouilleRetrieverPack to add support for document metadata

* Method updates

* Linting

---------

Co-authored-by: Ram <ram@Rams-MacBook-Pro.local>
  • Loading branch information
0-hero and Ram authored Jan 26, 2024
1 parent f41dab0 commit 7e85d56
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion llama_hub/llama_packs/ragatouille_retriever/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ def __init__(
)

doc_txts = [doc.get_content() for doc in documents]
doc_ids = [doc.doc_id for doc in documents]
doc_metadatas = [doc.metadata for doc in documents]

# index the documents
if index_path is None:
RAG = RAGPretrainedModel.from_pretrained("colbert-ir/colbertv2.0")
index_path = RAG.index(index_name=index_name, collection=doc_txts)
index_path = RAG.index(
index_name=index_name,
collection=doc_txts,
document_ids=doc_ids,
document_metadatas=doc_metadatas,
)
else:
RAG = RAGPretrainedModel.from_index(index_path)

Expand All @@ -89,6 +96,26 @@ def __init__(
self.custom_retriever, service_context=ServiceContext.from_defaults(llm=llm)
)

def add_documents(self, documents: List[Document]) -> None:
"""Add documents."""

doc_txts = [doc.get_content() for doc in documents]
doc_ids = [doc.doc_id for doc in documents]
doc_metadatas = [doc.metadata for doc in documents]

self.RAG.add_to_index(
new_collection=doc_txts,
new_document_ids=doc_ids,
new_document_metadatas=doc_metadatas,
)

def delete_documents(self, documents: List[Document]) -> None:
"""Delete documents."""

doc_ids = [doc.doc_id for doc in documents]

self.RAG.delete_from_index(document_ids=doc_ids)

def get_modules(self) -> Dict[str, Any]:
"""Get modules."""
return {
Expand Down

0 comments on commit 7e85d56

Please sign in to comment.