Saravanan666/pypi-org huggingface dataset:
Package: llama-index-packs-deeplake-deepmemory-retriever
DeepLake DeepMemory PackThis LlamaPack inserts your data into deeplake and instantiates adeepmemoryretriever, which will use deepmemory during runtime to increase RAG's retrieval accuracy (recall).CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackDeepMemoryRetrieverPack--download-dir./deepmemory_packYou can then inspect the files at./deepmemory_packand use them as a template for your own project!Code UsageYou can download the pack to a./deepmemory_packdirectory:fromllama_hub.llama_packimportdownload_llama_pack# download and install dependenciesDeepMemoryRetriever=download_llama_pack("DeepMemoryRetrieverPack","./deepmemory_pack")From here, you can use the pack, or inspect and modify the pack in./deepmemory_pack.Then, you can set up the pack like so:# setup pack argumentsfromllama_index.core.vector_stores.typesimportMetadataInfo,VectorStoreInfonodes=[...]# create the packdeepmemory_pack=DeepMemoryRetriever(dataset_path="llama_index",overwrite=False,nodes=nodes,)Therun()function is a light wrapper aroundquery_engine.query().response=deepmemory_pack.run("Tell me a bout a Music celebritiy.")You can also use modules individually.# use the retrieverretriever=deepmemory_pack.retrievernodes=retriever.retrieve("query_str")# use the query enginequery_engine=deepmemory_pack.query_engineresponse=query_engine.query("query_str")
Package: llama-index-packs-deeplake-multimodal-retrieval
DeepLake DeepMemory PackThis LlamaPack inserts your multimodal data (texts, images) into deeplake and instantiates an deeplake retriever, which will use clip for embedding images and GPT4-V during runtime.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackDeepLakeMultimodalRetrieverPack--download-dir./deeplake_multimodal_packYou can then inspect the files at./deeplake_multimodal_packand use them as a template for your own project!Code UsageYou can download the pack to a./deeplake_multimodal_packdirectory:fromllama_hub.llama_packimportdownload_llama_pack# download and install dependenciesDeepLakeMultimodalRetriever=download_llama_pack("DeepLakeMultimodalRetrieverPack","./deeplake_multimodal_pack")From here, you can use the pack, or inspect and modify the pack in./deepmemory_pack.Then, you can set up the pack like so:# setup pack argumentsfromllama_index.core.vector_stores.typesimportMetadataInfo,VectorStoreInfo# collection of image and text nodesnodes=[...]# create the packdeeplake_pack=DeepLakeMultimodalRetriever(nodes=nodes,dataset_path="llama_index",overwrite=False)Therun()function is a light wrapper aroundSimpleMultiModalQueryEngine.response=deeplake_pack.run("Tell me a bout a Music celebritiy.")You can also use modules individually.# use the retrieverretriever=deeplake_pack.retrievernodes=retriever.retrieve("query_str")# use the query enginequery_engine=deeplake_pack.query_engineresponse=query_engine.query("query_str")
Package: llama-index-packs-dense-x-retrieval
Dense-X-Retrieval PackThis LlamaPack creates a query engine that uses aRecursiveRetrieverin llama-index to fetch nodes based on propoistions extracted from each node.This follows the idea from the paperDense X Retrieval: What Retrieval Granularity Should We Use?.From the paper, a proposition is described as:Propositions are defined as atomic expressions within text, each encapsulating a distinct factoid and presented in a concise, self-contained natural language format.We use the provided OpenAI prompt from their paper to generate propositions, which are then embedded and used to retrieve their parent node chunks.NOTE:While the paper uses a fine-tuned model to extract propositions, it is unreleased at the time of writing. Currently, this pack uses the LLM to extract propositions, which can be expensive for large amounts of data.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackDenseXRetrievalPack--download-dir./dense_packYou can then inspect the files at./dense_packand use them as a template for your own project!Code UsageYou can download the pack to a the./dense_packdirectory:fromllama_indeximportSimpleDirectoryReaderfromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesDenseXRetrievalPack=download_llama_pack("DenseXRetrievalPack","./dense_pack")documents=SimpleDirectoryReader("./data").load_data()# uses the LLM to extract propositions from every document/node!dense_pack=DenseXRetrievalPack(documents)Therun()function is a light wrapper aroundquery_engine.query().response=dense_pack.run("What can you tell me about LLMs?")print(response)See thenotebook on llama-hubfor a full example.
Package: llama-index-packs-evaluator-benchmarker
Evaluator Benchmarker PackA pack for quick computation of benchmark results of your own LLM evaluator
on an Evaluation llama-dataset. Specifically, this pack supports benchmarking
an appropriate evaluator on the following llama-datasets:LabelledEvaluatorDatasetfor single-grading evaluationsLabelledPairwiseEvaluatorDatasetfor pairwise-grading evaluationsThese llama-datasets can be downloaed fromllama-hub.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackEvaluatorBenchmarkerPack--download-dir./evaluator_benchmarker_packYou can then inspect the files at./evaluator_benchmarker_packand use them as a template for your own project!Code UsageYou can download the pack to the./evaluator_benchmarker_packdirectory through python
code as well. The sample script below demonstrates how to constructEvaluatorBenchmarkerPackusing aLabelledPairwiseEvaluatorDatasetdownloaded fromllama-huband aPairwiseComparisonEvaluatorthat uses GPT-4 as the LLM. Note though that this pack
can also be used on aLabelledEvaluatorDatasetwith aBaseEvaluatorthat performs
single-grading evaluation — in this case, the usage flow remains the same.fromllama_index.core.llama_datasetimportdownload_llama_datasetfromllama_index.core.llama_packimportdownload_llama_packfromllama_index.core.evaluationimportPairwiseComparisonEvaluatorfromllama_index.core.llmsimportOpenAIfromllama_indeximportServiceContext# download a LabelledRagDataset from llama-hubpairwise_dataset=download_llama_dataset("MiniMtBenchHumanJudgementDataset","./data")# define your evaluatorgpt_4_context=ServiceContext.from_defaults(llm=OpenAI(temperature=0,model="gpt-4"),)evaluator=PairwiseComparisonEvaluator(service_context=gpt_4_context)# download and install dependenciesEvaluatorBenchmarkerPack=download_llama_pack("EvaluatorBenchmarkerPack","./pack")# construction requires an evaluator and an eval_datasetevaluator_benchmarker_pack=EvaluatorBenchmarkerPack(evaluator=evaluator,eval_dataset=pairwise_dataset,show_progress=True,)# PERFORM EVALUATIONbenchmark_df=evaluator_benchmarker_pack.run()# async arun() also supportedprint(benchmark_df)Output:number_examples                1689
inconclusives                  140
ties                           379
agreement_rate_with_ties       0.657844
agreement_rate_without_ties    0.828205Note thatevaluator_benchmarker_pack.run()will also save thebenchmark_dffiles in the same directory..
└──benchmark.csv
Package: llama-index-packs-fusion-retriever
Fusion Retriever PacksHybrid Fusion PackThis LlamaPack provides an example of our hybrid fusion retriever method.This specific template fuses results from our vector retriever and bm25 retriever; of course, you can provide any template you want.Check out thenotebook here.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackHybridFusionRetrieverPack--download-dir./hybrid_fusion_packYou can then inspect the files at./hybrid_fusion_packand use them as a template for your own project.Code UsageYou can download the pack to a the./hybrid_fusion_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesHybridFusionRetrieverPack=download_llama_pack("HybridFusionRetrieverPack","./hybrid_fusion_pack")From here, you can use the pack, or inspect and modify the pack in./hybrid_fusion_pack.Then, you can set up the pack like so:# create the packhybrid_fusion_pack=HybridFusionRetrieverPack(nodes,chunk_size=256,vector_similarity_top_k=2,bm25_similarity_top_k=2)Therun()function is a light wrapper aroundquery_engine.query().response=hybrid_fusion_pack.run("Tell me about a Music celebritiy.")You can also use modules individually.# use the fusion retrievernodes=hybrid_fusion_pack.fusion_retriever.retrieve("query_str")# use the vector retrievernodes=hybrid_fusion_pack.vector_retriever.retrieve("query_str")# use the bm25 retrievernodes=hybrid_fusion_pack.bm25_retriever.retrieve("query_str")# get the query enginequery_engine=hybrid_fusion_pack.query_engineQuery Rewriting Retriever PackThis LlamaPack provides an example of query rewriting through our fusion retriever.This specific template takes in a single retriever, and generates multiple queries against the retriever, and then fuses the results together.Check out thenotebook here.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackQueryRewritingRetrieverPack--download-dir./query_rewriting_packYou can then inspect the files at./query_rewriting_packand use them as a template for your own project.Code UsageYou can download the pack to a the./query_rewriting_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesQueryRewritingRetrieverPack=download_llama_pack("QueryRewritingRetrieverPack","./query_rewriting_pack")From here, you can use the pack, or inspect and modify the pack in./query_rewriting_pack.Then, you can set up the pack like so:# create the packquery_rewriting_pack=QueryRewritingRetrieverPack(nodes,chunk_size=256,vector_similarity_top_k=2,)Therun()function is a light wrapper aroundquery_engine.query().response=query_rewriting_pack.run("Tell me a bout a Music celebritiy.")You can also use modules individually.# use the fusion retrievernodes=query_rewriting_pack.fusion_retriever.retrieve("query_str")# use the vector retrievernodes=query_rewriting_pack.vector_retriever.retrieve("query_str")# get the query enginequery_engine=query_rewriting_pack.query_engine
Package: llama-index-packs-fuzzy-citation
Fuzzy Citation Query Engine PackCreates and runs aCustomQueryEngine--FuzzCitationQueryEngine-- which post-processes response objects to identify source sentences using fuzzy matching.The identified sentences are available in theresponse.metadatadictionary, containing a mapping of(response_sentence, source_chunk)->{"start_char_idx": idx, "end_char_idx": idx, "node" node}. The start/end idxs represent the character indexes in the node text that the source chunk comes from.The fuzzy matching usesfuzz.ratio()to compare sentences. The default threshold score is 50.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackFuzzyCitationEnginePack--download-dir./fuzzy_citation_packYou can then inspect the files at./fuzzy_citation_packand use them as a template for your own project!Code UsageYou can download the pack to a the./fuzzy_citation_packdirectory:fromllama_indeximportDocument,VectorStoreIndexfromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesFuzzyCitationEnginePack=download_llama_pack("FuzzyCitationEnginePack","./fuzzy_citation_pack")index=VectorStoreIndex.from_documents([Document.example()])query_engine=index.as_query_engine()fuzzy_engine=FuzzyCitationEnginePack(query_engine,threshold=50)Therun()function is a light wrapper aroundquery_engine.query(). The response will have metadata attached to it indicating the fuzzy citations.response=fuzzy_engine.run("What can you tell me about LLMs?")# print source sentencesprint(response.metadata.keys())# print full source sentence infoprint(response.metadata)See thenotebook on llama-hubfor a full example.
Package: llama-index-packs-gmail-openai-agent
Gmail OpenAI Agent PackCreate an OpenAI agent pre-loaded with a tool to interact with Gmail. The tool used is theGmail LlamaHub tool.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackGmailOpenAIAgentPack--download-dir./gmail_packYou can then inspect the files at./gmail_packand use them as a template for your own project!Code UsageYou can download the pack to a the./gmail_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesGmailOpenAIAgentPack=download_llama_pack("GmailOpenAIAgentPack","./gmail_pack")gmail_agent_pack=GmailOpenAIAgentPack()From here, you can use the pack, or inspect and modify the pack in./gmail_pack.Therun()function is a light wrapper aroundagent.chat().response=gmail_agent_pack.run("What is my most recent email?")You can also use modules individually.# Use the agentagent=gmail_agent_pack.agentresponse=agent.chat("What is my most recent email?")# Use the tool spec in another agentfromllama_index.core.agentsimportReActAgenttool_spec=gmail_agent_pack.tool_specagent=ReActAgent.from_tools(tool_spec.to_tool_lost())
Package: llama-index-packs-gradio-agent-chat
Gradio Chat With Your LlamaIndex AgentCreate a LlamaIndex Agent (i.e.,BaseAgent) and quickly chat with it using
this pack's Gradio Chatbot interface.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackGradioAgentChatPack--download-dir./gradio_agent_chatYou can then inspect the files at./gradio_agent_chatand use them as a template for your own project!To run the app directly, use in your terminal:exportOPENAI_API_KEY="sk-...python ./gradio_agent_chat/base.py
Package: llama-index-packs-gradio-react-agent-chatbot
Gradio ReActAgent Chatbot PackCreate a ReActAgent Chatbot equipped with two LlamaHub tools, namely:ArxivToolSpecand Wikipedia tool andWikipediaToolSpec.This pack's Gradio app is built using GradioBlocks. User messages are submitted
via aTextBoxBlock, which are then handled by a LlamaIndexReActAgentto generate a
response (calling required tools). The result is then sent to aChatbotBlock —
additionally the agent's thoughts are captured in anHTMLBlock.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackGradioReActAgentPack--download-dir./gradio_react_agent_chatbotYou can then inspect the files at./gradio_react_agent_chatbotand use them as a template for your own project!To run the app directly, use in your terminal:exportOPENAI_API_KEY="sk-...python ./gradio_react_agent_pack/base.py
Package: llama-index-packs-infer-retrieve-rerank
Infer-Retrieve-Rerank LlamaPackThis is our implementation of the paper"In-Context Learning for Extreme Multi-Label Classificationby Oosterlinck et al.The paper proposes "infer-retrieve-rerank", a simple paradigm using frozen LLM/retriever models that can do "extreme"-label classification (the label space is huge).Given a user query, use an LLM to predict an initial set of labels.For each prediction, retrieve the actual label from the corpus.Given the final set of labels, rerank them using an LLM.All of these can be implemented as LlamaIndex abstractions.A full notebook guide can be foundhere.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackInferRetrieveRerankPack--download-dir./infer_retrieve_rerank_packYou can then inspect the files at./infer_retrieve_rerank_packand use them as a template for your own project!Code UsageYou can download the pack to a./infer_retrieve_rerank_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesInferRetrieveRerankPack=download_llama_pack("InferRetrieveRerankPack","./infer_retrieve_rerank_pack")From here, you can use the pack, or inspect and modify the pack in./infer_retrieve_rerank_pack.Then, you can set up the pack like so:# create the packpack=InferRetrieveRerankPack(labels,# list of all label stringsllm=llm,pred_context="<pred_context>",reranker_top_n=3,verbose=True,)Therun()function runs predictions.pred_reactions=pack.run(inputs=[s["text"]forsinsamples])You can also use modules individually.# call the llm.complete()llm=pack.llmlabel_retriever=pack.label_retriever
Package: llama-index-packs-llama-dataset-metadata
LlamaDataset Metadata PackAs part of theLlamaDatasetsubmission package intollamahub,
two metadata files are required, namely:card.jsonandREADME.md. This pack
creates these two files and saves them to disk to help expedite the submission
process.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackLlamaDatasetMetadataPack--download-dir./llama_dataset_metadata_packYou can then inspect the files at./llama_dataset_metadata_packand use them as a template for your own project!Code UsageYou can download the pack to the./llama_dataset_metadata_packdirectory through python
code as well. The sample script below demonstrates how to constructLlamaDatasetMetadataPackusing aLabelledRagDatasetdownloaded fromllama-huband a simple RAG pipeline
built off of its source documents.fromllama_index.core.llama_packimportdownload_llama_pack# Download and install dependenciesLlamaDatasetMetadataPack=download_llama_pack("LlamaDatasetMetadataPack","./llama_dataset_metadata_pack")# construction requires a query_engine, a rag_dataset, and optionally a judge_llmllama_dataset_metadata_pack=LlamaDatasetMetadataPack()# create and save `card.json` and `README.md` to diskdataset_description=("A labelled RAG dataset based off an essay by Paul Graham, consisting of ""queries, reference answers, and reference contexts.")llama_dataset_metadata_pack.run(name="Paul Graham Essay Dataset",description=dataset_description,rag_dataset=rag_dataset,# defined earlier not shown hereindex=index,# defined earlier not shown herebenchmark_df=benchmark_df,# defined earlier not shown herebaseline_name="llamaindex",)NOTE: this pack should be used only after performing a RAG evaluation (i.e., by
usingRagEvaluatorPackon aLabelledRagDataset). In the code snippet above,index,rag_dataset, andbenchmark_dfare all objects that you'd expect to
have only after performing the RAG evaluation as mention in the previous sentence.
Package: llama-index-packs-llava-completion
LLaVA Completion PackThis LlamaPack creates the LLaVA multimodal model, and runs itscompleteendpoint to execute queries.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackLlavaCompletionPack--download-dir./llava_packYou can then inspect the files at./llava_packand use them as a template for your own project!Code UsageYou can download the pack to a./llava_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesLlavaCompletionPack=download_llama_pack("LlavaCompletionPack","./llava_pack")From here, you can use the pack, or inspect and modify the pack in./llava_pack.Then, you can set up the pack like so:# create the packllava_pack=LlavaCompletionPack(image_url="./images/image1.jpg")Therun()function is a light wrapper aroundllm.complete().response=llava_pack.run("What dinner can I cook based on the picture of the food in the fridge?")You can also use modules individually.# call the llm.complete()llm=llava_pack.llmresponse=llm.complete("query_str")
Package: llama-index-packs-multidoc-autoretrieval
Multi-Document AutoRetrieval (with Weaviate) PackThis LlamaPack implements structured hierarchical retrieval over multiple documents, using multiple @weaviate_io collections.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackMultiDocAutoRetrieverPack--download-dir./multidoc_autoretrieval_packYou can then inspect the files at./multidoc_autoretrieval_packand use them as a template for your own project!Code UsageYou can download the pack to a the./multidoc_autoretrieval_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesMultiDocAutoRetrieverPack=download_llama_pack("MultiDocAutoRetrieverPack","./multidoc_autoretrieval_pack")From here, you can use the pack. To initialize it, you need to define a few arguments, see below.Then, you can set up the pack like so:# setup pack argumentsfromllama_index.core.vector_stores.typesimportMetadataInfo,VectorStoreInfoimportweaviate# cloudauth_config=weaviate.AuthApiKey(api_key="<api_key>")client=weaviate.Client("https://<cluster>.weaviate.network",auth_client_secret=auth_config,)vector_store_info=VectorStoreInfo(content_info="Github Issues",metadata_info=[MetadataInfo(name="state",description="Whether the issue is `open` or `closed`",type="string",),...,],)# metadata_nodes is set of nodes with metadata representing each document# docs is the source docs# metadata_nodes and docs must be the same lengthmetadata_nodes=[TextNode(...,metadata={...}),...]docs=[Document(...),...]pack=MultiDocAutoRetrieverPack(client,"<metadata_index_name>","<doc_chunks_index_name>",metadata_nodes,docs,vector_store_info,auto_retriever_kwargs={# any kwargs for the auto-retriever...},)Therun()function is a light wrapper aroundquery_engine.query().response=pack.run("Tell me a bout a Music celebritiy.")You can also use modules individually.# use the retrieverretriever=pack.retrievernodes=retriever.retrieve("query_str")# use the query enginequery_engine=pack.query_engineresponse=query_engine.query("query_str")
Package: llama-index-packs-multi-document-agents
Multi-Document Agents PackThis LlamaPack provides an example of our multi-document agents.This specific template shows the e2e process of building this. Given a set
of documents, the pack will build our multi-document agents architecture.setup a document agent over agent doc (capable of QA and summarization)setup a top-level agent over doc agentsDuring query-time, do "tool retrieval" to return the set of relevant candidate documents, and then do retrieval within each document.Check out thenotebook here.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackMultiDocumentAgentsPack--download-dir./multi_doc_agents_packYou can then inspect the files at./multi_doc_agents_packand use them as a template for your own project.Code UsageYou can download the pack to a the./multi_doc_agents_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesMultiDocumentAgentsPack=download_llama_pack("MultiDocumentAgentsPack","./multi_doc_agents_pack")From here, you can use the pack, or inspect and modify the pack in./multi_doc_agents_pack.Then, you can set up the pack like so:# imagine documents on different citiesdocs=...doc_titles=["Toronto","Seattle","Houston","Chicago"]doc_descriptions=["<Toronto description>","<Seattle description>","<Houston description>","<Chicago description>",]# create the pack# get documents from any data loadermulti_doc_agents_pack=MultiDocumentAgentsPack(docs,doc_titles,doc_descriptions)Therun()function is a light wrapper aroundquery_engine.query().response=multi_doc_agents_pack.run("Tell me the demographics of Houston, and then compare with the demographics of Chicago")You can also use modules individually.# get the top-level agenttop_agent=multi_doc_agents_pack.top_agent# get the object index (which indexes all document agents, can return top-k# most relevant document agents as tools given user query)obj_index=multi_doc_agents_pack.obj_index# get document agentsdoc_agents=multi_doc_agents_pack.agents