Saravanan666/pypi-org huggingface dataset:
Package: llama-index-packs-self-rag
Simple self-RAG short form packThis LlamaPack implements (*in short form) theself-RAG paper by Akari et al..This paper presents a novel framework called Self-Reflective Retrieval-Augmented Generation (SELF-RAG). Which aims to enhance the quality and factuality of large language models (LLMs) by combining retrieval and self-reflection mechanisms.The implementation is adapted from the authorimplementationA full notebook guide can be foundhere.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackSelfRAGPack--download-dir./self_rag_packYou can then inspect the files at./self_rag_packand use them as a template for your own project!Code UsageWe will show you how to import the agent from these files!
The implementation uses llama-cpp, to download the relevant models (be sure to replace DIR_PATH)pip3install-qhuggingface-hub
huggingface-clidownloadm4r1/selfrag_llama2_7b-GGUFselfrag_llama2_7b.q4_k_m.gguf--local-dir"<DIR_PATH>"--local-dir-use-symlinksFalsefromllama_index.llama_packimportdownload_llama_pack# download and install dependenciesSelfRAGPack=download_llama_pack("SelfRAGPack","./self_rag_pack")From here, you can use the pack. You can import the relevant modules from the download folder (in the example below we assume it's a relative import or the directory
has been added to your system path).fromself_rag_pack.baseimportSelfRAGQueryEnginequery_engine=SelfRAGQueryEngine(model_path=model_path,retriever=retriever,verbose=True)response=query_engine.query("Who won best Director in the 1972 Academy Awards?")You can also use/initialize the pack directly.fromllm_compiler_agent_pack.baseimportSelfRAGPackagent_pack=SelfRAGPack(model_path=model_path,retriever=retriever,verbose=True)Therun()function is a light wrapper aroundagent.chat().response=pack.run("Who won best Director in the 1972 Academy Awards?")
Package: llama-index-packs-sentence-window-retriever
Sentence Window RetrieverThis LlamaPack provides an example of our sentence window retriever.This specific template shows the e2e process of building this. It loads
a document, chunks it up, adds surrounding context as metadata to each chunk,
and during retrieval inserts the context back into each chunk for response synthesis.Check out thenotebook here.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackSentenceWindowRetrieverPack--download-dir./sentence_window_retriever_packYou can then inspect the files at./sentence_window_retriever_packand use them as a template for your own project.Code UsageYou can download the pack to a the./sentence_window_retriever_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesSentenceWindowRetrieverPack=download_llama_pack("SentenceWindowRetrieverPack","./sentence_window_retriever_pack")From here, you can use the pack, or inspect and modify the pack in./sentence_window_retriever_pack.Then, you can set up the pack like so:# create the pack# get documents from any data loadersentence_window_retriever_pack=SentenceWindowRetrieverPack(documents,)Therun()function is a light wrapper aroundquery_engine.query().response=sentence_window_retriever_pack.run("Tell me a bout a Music celebritiy.")You can also use modules individually.# get the sentence vector indexindex=sentence_window_retriever_pack.sentence_index# get the node parsernode_parser=sentence_window_retriever_pack.node_parser# get the metadata replacement postprocessorpostprocessor=sentence_window_retriever_pack.postprocessor# get the query enginequery_engine=sentence_window_retriever_pack.query_engine
Package: llama-index-packs-snowflake-query-engine
Snowflake Query Engine PackThis LlamaPack usessnowflake-sqlalchemyto connect to Snowflake, then callsNLSQLTableQueryEngineto query data.UsageYou can download the pack to a the./snowflake_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesSnowflakeQueryEnginePack=download_llama_pack("SnowflakeQueryEnginePack","./snowflake_pack")From here, you can use the pack, or inspect and modify the pack in./snowflake_pack.NLSQLTableQueryEngineuses OpenAI models by default, ensure you set your OpenAI API key.You can set up the pack by passing in the Snowflake connection details and the table(s):# create the packsnowflake_pack=SnowflakeQueryEnginePack(user="<USER>",password="<PASSWORD>",account="<ORG>-<ACCOUNT>",database="<DATABASE>",schema="<SCHEMA>",warehouse="<WAREHOUSE>",role="<ROLE>",tables=["<TABLE1>","<TABLE2>",...],)Therun()function is a light wrapper aroundquery_engine.query(). See below a sample query run. You can add additional prompt in the query text.response=snowflake_pack.run("Give me the repo id with the most stars on 2023-12-01.")
Package: llama-index-packs-stock-market-data-query-engine
Stock Market Data Query Engine PackQuery and retrieve historical market data for a list of stock tickers. It utilizes Yahoo Finance(yfinance)to fetch historical stock prices.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackStockMarketDataQueryEnginePack--download-dir./stock_market_data_packYou can then inspect the files at./stock_market_data_packand use them as a template for your own project.Code UsageYou can download the pack to a the./stock_market_data_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesStockMarketDataQueryEnginePack=download_llama_pack("StockMarketDataQueryEnginePack","./stock_market_data_pack")From here, you can use the pack, or inspect and modify the pack in./stock_market_data_pack.Then, you can set up the pack like so:# create the packstock_market_data_pack=StockMarketDataQueryEnginePack(["MSFT"],period="1mo",)Therun()function is a light wrapper aroundquery_engine.query().response=stock_market_data_pack.run("What is the average closing price for MSFT?")
Package: llama-index-packs-streamlit-chatbot
Steamlit Chatbot PackBuild a chatbot powered by LlamaIndex that augments an LLM with the contents of Snowflake's Wikipedia page (or your own data).Takes user queries via Streamlit'sst.chat_inputand displays both user queries and model responses withst.chat_messageUses LlamaIndex to load and index data and create a chat engine that will retrieve context from that data to respond to each user queryUI will stream each answer from the LLMCLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:pipinstallllama-indexllamaindex-clidownload-llamapackStreamlitChatPack--download-dir./streamlit_chatbot_packYou can then inspect the files at./streamlit_chatbot_packand use them as a template for your own project!To run the app directly, use in your terminal:exportOPENAI_API_KEY="sk-..."streamlitrun./streamlit_chatbot_pack/base.py
Package: llama-index-packs-subdoc-summary
LlamaIndex Packs Integration: Subdoc-SummaryThis LlamaPack provides an advanced technique for injecting each chunk with "sub-document" metadata. This context augmentation technique is helpful for both retrieving relevant context and for synthesizing correct answers.It is a step beyond simply adding a summary of the document as the metadata to each chunk. Within a long document, there can be multiple distinct themes, and we want each chunk to be grounded in global but relevant context.This technique was inspired by our "Practical Tips and Tricks" video:https://www.youtube.com/watch?v=ZP1F9z-S7T0.Installationpipinstallllama-indexllama-index-packs-subdoc-summaryCLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackSubDocSummaryPack--download-dir./subdoc_summary_packYou can then inspect the files at./subdoc_summary_packand use them as a template for your own project.Code UsageYou can download the pack to a the./subdoc_summary_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesSubDocSummaryPack=download_llama_pack("SubDocSummaryPack","./subdoc_summary_pack")# You can use any llama-hub loader to get documents!subdoc_summary_pack=SubDocSummaryPack(documents,parent_chunk_size=8192,# default,child_chunk_size=512,# defaultllm=OpenAI(model="gpt-3.5-turbo"),embed_model=OpenAIEmbedding(),)Initializing the pack will split documents into parent chunks and child chunks. It will inject parent chunk summaries into child chunks, and index the child chunks.Running the pack will run the query engine over the vectorized child chunks.response=subdoc_summary_pack.run("<query>",similarity_top_k=2)
Package: llama-index-packs-sub-question-weaviate
Sub Question Query EngineThis LlamaPack inserts your data intoWeaviateand uses theSub-Question Query Enginefor your RAG application.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackWeaviateSubQuestionPack--download-dir./weaviate_packYou can then inspect the files at./weaviate_packand use them as a template for your own project.Code UsageYou can download the pack to a the./weaviate_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesWeaviateSubQuestionPack=download_llama_pack("WeaviateSubQuestionPack","./weaviate_pack")From here, you can use the pack, or inspect and modify the pack in./weaviate_pack.Then, you can set up the pack like so:# setup pack argumentsfromllama_index.core.vector_stores.typesimportMetadataInfo,VectorStoreInfovector_store_info=VectorStoreInfo(content_info="brief biography of celebrities",metadata_info=[MetadataInfo(name="category",type="str",description=("Category of the celebrity, one of [Sports Entertainment, Business, Music]"),),],)importweaviateclient=weaviate.Client()nodes=[...]# create the packweaviate_pack=WeaviateSubQuestion(collection_name="test",vector_store_info=vector_store_index,nodes=nodes,client=client,)Therun()function is a light wrapper aroundquery_engine.query().response=weaviate_pack.run("Tell me a bout a Music celebritiy.")You can also use modules individually.# use the retrieverretriever=weaviate_pack.retrievernodes=retriever.retrieve("query_str")# use the query enginequery_engine=weaviate_pack.query_engineresponse=query_engine.query("query_str")
Package: llama-index-packs-trulens-eval-packs
TruLens-Eval Llama-PackThe best way to support TruLens is to give us a ⭐ onGitHuband join ourslack community!TruLens provides three Llamma Packs for LLM app observability:The first is theTruLensRAGTriadPack(context relevance, groundedness, answer relevance). This triad holds the key to detecting hallucination.Second, is theTruLensHarmlessPackincluding moderation and safety evaluations like criminality, violence and more.Last is theTruLensHelpfulPack, including evaluations like conciseness and language match.No matter which TruLens LlamaPack you choose, all three provide evaluation and tracking for your LlamaIndex app withTruLens, an open-source LLM observability library fromTruEra.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackTruLensRAGTriadPack--download-dir./trulens_packYou can then inspect the files at./trulens_packand use them as a template for your own project.Code UsageYou can download each pack to a./trulens_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesTruLensRAGTriadPack=download_llama_pack("TruLensRAGTriadPack","./trulens_pack")From here, you can use the pack, or inspect and modify the pack in./trulens_pack.Then, you can set up the pack like so:importosos.environ["OPENAI_API_KEY"]="sk-..."fromtqdm.autoimporttqdmfromllama_index.core.node_parserimportSentenceSplitterfromllama_index.readers.webimportSimpleWebPageReaderdocuments=SimpleWebPageReader(html_to_text=True).load_data(["http://paulgraham.com/worked.html"])splitter=SentenceSplitter()nodes=splitter.get_nodes_from_documents(documents)trulens_ragtriad_pack=TruLensRAGTriadPack(nodes=nodes,app_id="Query Engine v1: RAG Triad Evals")Then run your queries and evaluate!queries=["What did Paul Graham do growing up?","When and how did Paul Graham's mother die?","What, in Paul Graham's opinion, is the most distinctive thing about YC?","When and how did Paul Graham meet Jessica Livingston?","What is Bel, and when and where was it written?",]forqueryintqdm(queries):print("Query")print("=====")print(query)print()response=trulens_ragtriad_pack.run(query)print("Response")print("========")print(response)You can access the internals of the LlamaPack, including your TruLens session and your query engine, via theget_modulesmethod.modules=trulens_ragtriad_pack.get_modules()tru=modules["session"]index=modules["index"]query_engine=modules["query_engine"]tru_query_engine=modules["tru_query_engine"]tru.get_leaderboard(app_ids=["Query Engine v1: RAG Triad Evals"])ResourcesThere is a more complete notebook demoavailable in the llama-hub repo.Check out theTruLens documentationfor more information!
Package: llama-index-packs-vanna
Vanna AI LLamaPackVanna AI is an open-source RAG framework for SQL generation. It works in two steps:Train a RAG model on your dataAsk questions (use reference corpus to generate SQL queries that can run on your db).Check out theGithub projectand thedocsfor more details.This LlamaPack creates a simpleVannaQueryEnginewith vanna, ChromaDB and OpenAI, and allows you to train and ask questions over a SQL database.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackVannaPack--download-dir./vanna_packYou can then inspect the files at./vanna_packand use them as a template for your own project!Code UsageYou can download the pack to a./vanna_packdirectory:fromllama_index.llama_packimportdownload_llama_pack# download and install dependenciesVannaPack=download_llama_pack("VannaPack","./vanna_pack")From here, you can use the pack, or inspect and modify the pack in./vanna_pack.Then, you can set up the pack like so:pack=VannaPack(openai_api_key="<openai_api_key>",sql_db_url="chinook.db",openai_model="gpt-3.5-turbo",)Therun()function is a light wrapper aroundllm.complete().response=pack.run("List some sample albums")You can also use modules individually.query_engine=pack.get_modules()["vanna_query_engine"]
Package: llama-index-packs-vectara-rag
Vectara RAG PackThis LlamaPack provides an end-to-end Retrieval Augmented Generation flow using Vectara.Before you start, if you have not done so already, you would need to follow these steps:Create afree Vectara account.Create acorpusto store your dataCreate anAPI keywith QueryService and IndexService access so you can access this corpusYou can configure your.envfile or provide these arguments directly when creating your VectaraIndex:VECTARA_CUSTOMER_ID=your_customer_id
VECTARA_CORPUS_ID=your_corpus_id
VECTARA_API_KEY=your-vectara-api-keyCLI UsageYou can download the Vectara llamapack directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackVectaraRagPack--download-dir./vectara_rag_packFeel free to inspect the files at./vectara_rag_packand use them as a template for your own project!Code UsageYou can download the pack to a./vectara_rag_packdirectory:fromllama_index.core.llama_packimportdownload_llama_packVectaraRAG=download_llama_pack("VectaraRagPack","./vectara_rag_pack")Then, you can set up the pack in two ways:If you want to ingest documents into the Vectara Corpus:nodes=[...]vectara=VectaraRAG(nodes=nodes)If you already indexed data on Vectara, and just want to use the retrieval/query functionality:vectara=VectaraRAG()Additional optional arguments to VectaraRAG:similarity_top_k: determines the number of results to return. Defaults to 5.n_sentences_beforeandn_sentences_after: determine the number of sentences before/after the
matching fact to use with the summarization LLM. defaults to 2.vectara_query_mode: 'default' or 'mmr'summary_enabled: whether to generate summaries or not. Defaults to True.When summary_enabled is True, you can set the following:summary_response_lang: language to use (ISO 639-2 code) for summary generation. defaults to "eng".summary_num_results: number of results to use for summary generation. Defaults to 7.summary_prompt_name: name of the prompt to use for summary generation.
Defaults to 'vectara-summary-ext-v1.2.0'.
Scale customers can use 'vectara-summary-ext-v1.3.0whenvectara_query_modeis "mmr", you can set the following to control MMR:mmr_k: number of results to fetch for MMR, defaults to 50mmr_diversity_bias: number between 0 and 1 that determines the degree
of diversity among the results with 0 corresponding
to minimum diversity and 1 to maximum diversity. Defaults to 0.3.For example to use maximal diversity with MMR:vectara=VectaraRAG(vectara_query_mode="mmr",mmr_k=50,mmr_diversity_bias=1.0)Or if you want to include more results in the Vectara generated summarization you can try:vectara=VectaraRAG(summary_num_results=12)Once you have the Vectara RAG object, you can now use it as a retriever:# use the retrievernodes=vectara.retrieve("Is light a wave or a particle?")Or as a query engine (with Vectara summarization call):# use the query engineresponse=vectara._query_engine.query("Is light a wave or a particle?").responseNote that therun()function is a light wrapper aroundquery_engine.query().response=vectara.run("Is light a wave or a particle?").responseEnjoy your Vectara RAG pack!
Package: llama-index-packs-voyage-query-engine
Voyage Query Engine PackCreate a query engine using GPT4 andVoyage AIEmbeddings.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackVoyageQueryEnginePack--download-dir./voyage_packYou can then inspect the files at./voyage_packand use them as a template for your own project.Code UsageYou can download the pack to a the./voyage_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesVoyageQueryEnginePack=download_llama_pack("VoyageQueryEnginePack","./voyage_pack")# You can use any llama-hub loader to get documents!voyage_pack=VoyageQueryEnginePack(documents)From here, you can use the pack, or inspect and modify the pack in./voyage_pack.Therun()function is a light wrapper aroundindex.as_query_engine().query().response=voyage_pack.run("What did the author do growing up?",similarity_top_k=2)You can also use modules individually.# Use the index directlyindex=voyage_pack.indexquery_engine=index.as_query_engine()retriever=index.as_retriever()
Package: llama-index-packs-zephyr-query-engine
Zephyr Query Engine PackCreate a query engine using completely local and private models --HuggingFaceH4/zephyr-7b-betafor the LLM andBAAI/bge-base-en-v1.5for embeddings.CLI UsageYou can download llamapacks directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamapackZephyrQueryEnginePack--download-dir./zephyr_packYou can then inspect the files at./zephyr_packand use them as a template for your own project.Code UsageYou can download the pack to a the./zephyr_packdirectory:fromllama_index.core.llama_packimportdownload_llama_pack# download and install dependenciesZephyrQueryEnginePack=download_llama_pack("ZephyrQueryEnginePack","./zephyr_pack")# You can use any llama-hub loader to get documents!zephyr_pack=ZephyrQueryEnginePack(documents)From here, you can use the pack, or inspect and modify the pack in./zephyr_pack.Therun()function is a light wrapper aroundindex.as_query_engine().query().response=zephyr_pack.run("What did the author do growing up?",similarity_top_k=2)You can also use modules individually.# Use the llmllm=zephyr_pack.llmresponse=llm.complete("What is HuggingFace?")# Use the index directlyindex=zephyr_pack.indexquery_engine=index.as_query_engine()retriever=index.as_retriever()
Package: llama-index-readers-agent-search
AgentSearch LoaderThis framework facilitates seamless integration with the AgentSearch dataset or hosted search APIs (e.g. Search Engines) and with RAG-specialized LLM's (e.g. Search Agents).During query-time, the user passes in the query string, search provider (bing,agent-search), and RAG provider model (SciPhi/Sensei-7B-V1).To learn more, please refer to the documentationhere.UsageHere's an example usage of the AgentSearchReader.# Optionally set the API key in the env# import os# os.environ["SCIPHI_API_KEY"] = "..."fromllama_indeximportdownload_loaderAgentSearch=download_loader("AgentSearchReader")reader=AgentSearch()document=reader.load_data(query="latest news",)[0]# text = "The latest news encompasses ... and its consequences [2]."# metadata = {'related_queries': ['Details on the...', ...], 'search_results' : [...]}This loader is designed to be used as a way to load data intoLlamaIndexand/or subsequently used as a Tool in aLangChainAgent. Seeherefor examples.
Package: llama-index-readers-airbyte-cdk
Airbyte CDK LoaderThe Airbyte CDK Loader is a shim for sources created using theAirbyte Python CDK. It allows you to load data from any Airbyte source into LlamaIndex.InstallationInstall llama_hub:pip install llama_hubInstall airbyte-cdk:pip install airbyte-cdkInstall a source via git (or implement your own):pip install git+https://github.com/airbytehq/airbyte.git@master#egg=source_github&subdirectory=airbyte-integrations/connectors/source-githubUsageImplement and import your own source. You can find lots of resources for how to achieve this on theAirbyte documentation page.Here's an example usage of the AirbyteCdkReader.fromllama_indeximportdownload_loaderfromllama_hub.airbyte_cdkimportAirbyteCDKReaderfromsource_github.sourceimport(SourceGithub,)# this is just an example, you can use any source here - this one is loaded from the Airbyte Github repo via pip install git+https://github.com/airbytehq/airbyte.git@master#egg=source_github&subdirectory=airbyte-integrations/connectors/source-github`github_config={# ...}reader=AirbyteCDKReader(source_class=SourceGithub,config=github_config)documents=reader.load_data(stream_name="issues")By default all fields are stored as metadata in the documents and the text is set to the JSON representation of all the fields. Construct the text of the document by passing arecord_handlerto the reader:defhandle_record(record,id):returnDocument(doc_id=id,text=record.data["title"],extra_info=record.data)reader=AirbyteCDKReader(source_class=SourceGithub,config=github_config,record_handler=handle_record,)Lazy loadsThereader.load_dataendpoint will collect all documents and return them as a list. If there are a large number of documents, this can cause issues. By usingreader.lazy_load_datainstead, an iterator is returned which can be consumed document by document without the need to keep all documents in memory.Incremental loadsIf a stream supports it, this loader can be used to load data incrementally (only returning documents that weren't loaded last time or got updated in the meantime):reader=AirbyteCDKReader(source_class=SourceGithub,config=github_config)documents=reader.load_data(stream_name="issues")current_state=reader.last_state# can be pickled away or stored otherwiseupdated_documents=reader.load_data(stream_name="issues",state=current_state)# only loads documents that were updated since last timeThis loader is designed to be used as a way to load data intoLlamaIndexand/or subsequently used as a Tool in aLangChainAgent. Seeherefor examples.