Feb 2, 2024
Feb 2, 2024
What is QueryPipelines?
QueryPipelines is a set of declarative API provided by llama-index that allows users to connect different components of the RAG together very easily.
QueryPipelines provide a declarative query orchestration to compose workflows using llama-index modules efficiently with fewer lines of code.
There are two main ways to use a QueryPipelines:
As a sequential chain which is the easiest and most concise to implement
As a full Directed Acyclic Graph which is more expressive.
Here we will use the following components to implement an Advanced RAG workflow:
Sentence Window Retrieval :In this scheme each sentence in a document is embedded separately which provides great accuracy of the query to context cosine distance search.
In order to better reason upon the found context after fetching the most relevant single sentence we extend the context window by k sentences before and after the retrieved sentence and then send this extended context to LLM.
Hybrid Fusion Retriever: In this step, we fuse dense vector retriever with a BM25 based retriever. This will enable us to capture both semantic relations and keywords in our input queries. Since both of these retrievers calculate a score, we can use the reciprocal rerank algorithm to re-sort our nodes without using an additional models or excessive computation. This setup will also query 4 times, once with your original query, and generate 3 more queries.
LongContext Reorder: Models struggle to access significant details found in the center of extended contexts. A study observed that the best performance typically arises when crucial data is positioned at the start or conclusion of the input context. Additionally, as the input context lengthens, performance drops notably, even in models designed for long contexts. This module will re-order the retrieved nodes, which can be helpful in cases where a large top-k is needed.
Query Rewriting: Here we will use an LLM as a reasoning engine to modify user input in order to improve retrieval quality. We will ask the LLM to rewrite the user query.
Reranker : It uses the cross-encoders from the
sentence-transformer
package to re-order nodes, and returns the top N nodes. This is the final step before feeding our retrieved context to LLM in order to get the resulting answer.
Method 1: Implement Simple Sequential chain
Some pipelines are purely linear in nature i.e. the output of previous module directly goes as input to the next module. Here we will implement a RAG workflow comprising of query rewriting, sentence window retrieval and a response synthesizer using Long Context Reorder and Reranker.
Install required Dependencies
!pip install -qU llama-index llama-cpp-python pypdf sentence-transformers rank-bm25
Import Required Dependencies
from llama_index.postprocessor import SentenceTransformerRerank from llama_index.response_synthesizers import TreeSummarize from llama_index import ServiceContext from llama_index.query_pipeline import QueryPipeline from llama_index.text_splitter import SentenceSplitter from llama_index.node_parser import SimpleNodeParser # import os # from llama_index.llms import LlamaCPP from llama_index.llms.llama_utils import ( messages_to_prompt, completion_to_prompt, )
Load the Document
!mkdir Data!wget "htt!mkdir Data !wget "https://content.accion.org/wp-content/uploads/2018/08/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf" -P "/content/Data/esops.pdf"ps://content.accion.org/wp-content/uploads/2018/08/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf" -P "/content/Data/esops.pdf"
Instantiate the embedding model
from llama_index.embeddings import resolve_embed_model embed_model = resolve_embed_model("local:BAAI/bge-large-en-v1.5")
Instantiate the Large Language Model
# download the source model ! huggingface-cli download TheBloke/Mistral-7B-Instruct-v0.2-GGUF mistral-7b-instruct-v0.2.Q4_K_M.gguf --local-dir . --local-dir-use-symlinks False # llm = LlamaCPP( # You can pass in the URL to a GGML model to download it automatically #model_url=model_url, # optionally, you can set the path to a pre-downloaded model instead of model_url model_path=r"/content/mistral-7b-instruct-v0.2.Q4_K_M.gguf", temperature=0.1, max_new_tokens=256, # llama2 has a context window of 4096 tokens, but we set it lower to allow for some wiggle room context_window=8000, # kwargs to pass to __call__() generate_kwargs={}, # kwargs to pass to __init__() # set to at least 1 to use GPU model_kwargs={"n_gpu_layers": 0,"n_threads": int(os.cpu_count() /2)}, # transform inputs into Llama2 format messages_to_prompt=messages_to_prompt, completion_to_prompt=completion_to_prompt, verbose=True, )
Read the content of the document
from llama_index import SimpleDirectoryReader document = SimpleDirectoryReader("/content/Data/esops.pdf").load_data() # print(len(document)) # print(document[0]) # print(document[0].text) # print(document[0].metadata)
Split the documents into smaller chunks
SimpleNodeParser converts documents into a list of nodes. It offers flexibility in how the document is parsed, allowing for customization in terms of chunk size, overlap, and inclusion of metadata.
The SentenceSplitter is a type of text splitter that breaks down the text into sentences. This is useful when you want to maintain the integrity of individual sentences within each chunk.
# node_parser = SimpleNodeParser.from_defaults(paragraph_separator=r"\n●|\n-|\n", chunk_size=250, chunk_overlap=25, include_prev_next_rel=True, include_metadata=True ) split_nodes = node_parser.get_nodes_from_documents(document)
Prepare the document chunks to instantiate the SentenceWindowNode Parser
from llama_index.node_parser import SentenceWindowNodeParser from typing import List import re def custom_sentence_splitter(text: str) -> List[str]: return re.split(r'\n●|\n-|\n', text) swindow_node_parser = SentenceWindowNodeParser.from_defaults( sentence_splitter=custom_sentence_splitter, window_size=3, include_prev_next_rel=True, include_metadata=True )
Processing Nodes
For each base node, it generates sub-nodes using the SentenceWindowNodeParser (with custom settings). Then, it converts the base nodes and their corresponding sub-nodes into Index Node instances.
The final list of Index Node instances is stored in all nodes.
An IndexNode is a node object used in LlamaIndex. At its core, the IndexNode inherits properties from a TextNode, meaning it primarily represents textual content.
from llama_index.schema import IndexNode sub_node_parsers =[swindow_node_parser] all_nodes = [] for base_node in split_nodes: for parser in sub_node_parsers: sub_nodes = parser.get_nodes_from_documents([base_node]) sub_inodes = [ IndexNode.from_text_node(sn, base_node.node_id) for sn in sub_nodes ] all_nodes.extend(sub_inodes) # also add original node to node original_node = IndexNode.from_text_node(base_node, base_node.node_id) all_nodes.append(original_node) # all_nodes_dict = {n.node_id: n for n in all_nodes} # print(len(all_nodes)) # print(all_nodes[10].relationships) ##########################Response############### 642 {<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='6aca782c-4022-4154-9ee4-2e18323b0a7f', node_type=<ObjectType.TEXT: '1'>, metadata={'page_label': '2', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-03', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-03'}, hash='999e9ea95e0251e033db4ec63e21a68bf1f0264e5c94331d163871a757bff657'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='f9a3c5df-098e-4f39-b70a-9faac6afb28e', node_type=<ObjectType.TEXT: '1'>, metadata={'window': 'Part I: Intro to Options Plans •What is an ESOP? •What is an Option? •Lifecycle of a Startup ESOP •Common Terms in an Options Package •Why Issue Options to Employees ? ', 'original_text': '•Lifecycle of a Startup ESOP ', 'page_label': '2', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-03', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-03'}, hash='7b47bb35a9fcb812dc4221bf5303570d8e1b055c9188516e3dc639ce02f4453d'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='be4f9f95-e42a-42f3-ae78-3fc4882f3f5a', node_type=<ObjectType.TEXT: '1'>, metadata={'window': '•What is an Option? •Lifecycle of a Startup ESOP •Common Terms in an Options Package •Why Issue Options to Employees ? –A Defining Characteristic of Startup Culture –A Necessary Part of the Capital Structure ', 'original_text': '•Why Issue Options to Employees ? '}, hash='b1b3a421a0b2292bb8c2f13dc7da8c7d43e97f0d91d3a95689f1538167c254a1')}
Instantiate the ServiceContext
The ServiceContext in LlamaIndex is a utility container that bundles commonly used resources during the indexing and querying stages of a LlamaIndex pipeline or application.
service_context = ServiceContext.from_defaults(llm=llm,embed_model=embed_model)
Instantiate the VectorStoreIndex
A VectorStoreIndex in LlamaIndex is a type of index that uses vector representations of text for efficient retrieval of relevant context.
from llama_index import VectorStoreIndex vector_index_chunk = VectorStoreIndex( all_nodes, service_context=service_context )
Instantiate Longcontext Reorder
This module will re-order the retrieved nodes, which can be helpful in cases where a large top-k is needed.(llama_index.postprocessor.node.LongContextReorder)
from llama_index.postprocessor import LongContextReorder lim_reorder = LongContextReorder()
Instantiate RecursiveRetriever
The RecursiveRetriever is designed to recursively explore links from nodes to other retrievers or query engines. This means that when the retriever fetches nodes, if any of those nodes point to another retriever or query engine, the RecursiveRetriever will follow that link and query the linked retriever or engine as well.(llama_index.indices.vector_store.retrievers.retriever.VectorIndexRetriever)
from llama_index.retrievers import RecursiveRetriever # vector_retriever_chunk = vector_index_chunk.as_retriever(similarity_top_k=5) # retriever_chunk = RecursiveRetriever( "vector", retriever_dict={"vector": vector_retriever_chunk,"long_context":lim_reorder}, node_dict=all_nodes_dict, verbose=True, )
Persist the vectorstore
vector_index_chunk.set_index_id("vector_index") vector_index_chunk.storage_context.persist("./storage")
Rebuild the index
# rebuild storage context storage_context = StorageContext.from_defaults(persist_dir="storage") # load index vector_index_chunk = load_index_from_storage(storage_context, index_id="vector_index
Instantiate the Reranker
(llama_index.postprocessor.sbert_rerank.SentenceTransformerRerank)
import torch from llama_index.postprocessor import SentenceTransformerRerank reranker = SentenceTransformerRerank(model="cross-encoder/ms-marco-MiniLM-L-2-v2", top_n=5)
Instantiate the Hybrid/Fusion Retriever
(llama_index.retrievers.fusion_retriever.QueryFusionRetriever)
from llama_index.retrievers import BM25Retriever from llama_index.retrievers import QueryFusionRetriever # bm25_retriever = BM25Retriever.from_defaults(docstore=vector_index_chunk.docstore, similarity_top_k=5) # hybrid_retriever = QueryFusionRetriever( [vector_retriever_chunk, bm25_retriever], llm=llm, similarity_top_k=3, num_queries=4, # set this to 1 to disable query generation mode="reciprocal_rerank", use_async=True, verbose=True, # query_gen_prompt="...", # we could override the query generation prompt here )
# apply nested async to run in a notebook import nest_asyncio nest_asyncio.apply() # nodes_with_scores = hybrid_retriever.retrieve("What is Esops?") ##################RESPONSE############################ Llama.generate: prefix-match hit Generated queries: 1. "What is the meaning of ESOPs in business?" 2. "Explanation of Employee Stock Ownership Plans (ESOPs)" 3. "How do Employee Stock Ownership Plans (ESOPs) work?" since the num_queries is set to 4 the fusion retriever has generated 3 additional questions in addition to the orginal questions asked above
for node in nodes_with_scores: print(f"Text:{node.text}") print(f"Score:{node.score}") print(f"Metadata:{node.metadata}") print("\n\n") ######### Response ######### Text:What is an ESOP? •An Employee Stock Options Plan (ESOP) •An allocation of shares that will be granted to employees in the future in the form of stock options –How much equity should we set aside for employees? •A plan for how these options will be distributed: –How many shares will individual employees receive? –What terms will govern these grants? •The plan is as important as the allocation! Score:0.05 Metadata:{'page_label': '4', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'} Text:•An Employee Stock Options Plan (ESOP) Score:0.03333333333333333 Metadata:{'window': 'What is an ESOP? •An Employee Stock Options Plan (ESOP) •An allocation of shares that will be granted to employees in the future ', 'original_text': '•An Employee Stock Options Plan (ESOP) ', 'page_label': '4', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'} Text:Employee Stock Options Plan (ESOP) Model Score:0.03278688524590164 Metadata:{'window': 'Options Modeling – A Detailed Example Employee Stock Options Plan (ESOP) Model Year 0 Year 1 Year 2 Year 3 Year 4 Value Shares Value Shares Shr. Price Value Shares Shr. Price Value Shares Shr. Price', 'original_text': 'Employee Stock Options Plan (ESOP) Model', 'page_label': '40', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}
Define the Prompt
from llama_index.prompts import PromptTemplate prompt_str = "Please generate a concise question about {question}" prompt_tmpl = PromptTemplate(prompt_str)
Instantiate the Retriever Query Engine
from llama_index.query_engine import RetrieverQueryEngine query_engine_chunk = RetrieverQueryEngine.from_args( retriever_chunk,#RecursiveRetriever service_context=service_context, verbose=True, response_mode="compact", node_postprocessors=[LongContextReorder(),reranker] )
Chain Together all the advanced RAG components
q = QueryPipeline(chain=[prompt_tmpl,llm,retriever_chunk,query_engine_chunk],verbose=True) q.run(question="What is ESOPs?") ########## RESPOSNE LOG ############################### > Running module 7ef1f981-ba78-458a-8de0-35567e1b9a79 with input: question: What is ESOPs? > Running module b94523f8-26f3-44d7-8ef5-cdd08436eb22 with input: prompt: Please generate a concise question about What is ESOPs? Llama.generate: prefix-match hit > Running module 183049be-a37d-4c51-b824-11beb242933d with input: input: What are Employee Stock Ownership Plans (ESOPs) and how do they function? Retrieving with query id None: What are Employee Stock Ownership Plans (ESOPs) and how do they function? Retrieved node with id, entering: 82dcddb6-55e1-43fc-b1c2-0460460bae61 Retrieving with query id 82dcddb6-55e1-43fc-b1c2-0460460bae61: What are Employee Stock Ownership Plans (ESOPs) and how do they function? Retrieved node with id, entering: 8e157341-eb5d-40b6-97e7-8b03c320b0c1 Retrieving with query id 8e157341-eb5d-40b6-97e7-8b03c320b0c1: What are Employee Stock Ownership Plans (ESOPs) and how do they function? Retrieved node with id, entering: a64f70f9-1ce3-4091-b031-bf5c9a83ef43 Retrieving with query id a64f70f9-1ce3-4091-b031-bf5c9a83ef43: What are Employee Stock Ownership Plans (ESOPs) and how do they function? Retrieved node with id, entering: dac95671-01d8-4b83-8263-4eae8453615f Retrieving with query id dac95671-01d8-4b83-8263-4eae8453615f: What are Employee Stock Ownership Plans (ESOPs) and how do they function? Retrieved node with id, entering: cf76d79c-2249-44d4-a6d7-acfec1b0e787 Retrieving with query id cf76d79c-2249-44d4-a6d7-acfec1b0e787: What are Employee Stock Ownership Plans (ESOPs) and how do they function? > Running module e968a8c1-5c51-4112-8534-4684fb9d1f97 with input: input: [NodeWithScore(node=IndexNode(id_='82dcddb6-55e1-43fc-b1c2-0460460bae61', embedding=None, metadata={'page_label': '4', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path'... Llama.generate: prefix-match hit Generated queries: 1. "How is equity allocated to employees in an ESOP?" 2. "What is the difference between Silicon Valley companies and other industries in terms of equity distribution to employees?" 3. "What is the process for deciding the amount of equity to be granted to employees in an ESOP?" Llama.generate: prefix-match hit Response(response=' An Employee Stock Options Plan (ESOP) is a plan that allocates shares of a company that will be granted to employees in the future in the form of stock options. There are two approaches to creating an ESOP: top-down and bottom-up planning. Top-down planning involves deciding the total amount of equity to be granted to employees and allocating these shares to them over time. Bottom-up planning, on the other hand, specifically considers how much equity each employee should be awarded based on their position and uses this framework for individual equity grants. The goal is to get away from ad hoc equity awards and personal negotiations by standardizing both the amount of equity available to employees and the process by which packages are awarded. This practice is widely used in Silicon Valley companies and is a defining characteristic of startup culture.', source_nodes=[NodeWithScore(node=IndexNode(id_='a64f70f9-1ce3-4091-b031-bf5c9a83ef43', embedding=None, metadata={'page_label': '14', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='e26c1168-55a3-451f-9eb5-589e6f2acb3c', node_type=<ObjectType.DOCUMENT: '4'>, metadata={'page_label': '14', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, hash='397f29a610b2b0600d349e3cfb63b8f5833e19ae4958f60fef1609913e3f53ce'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='a65be1ae-ceeb-4cda-9744-6dbb9049f8a8', node_type=<ObjectType.TEXT: '1'>, metadata={'page_label': '13', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, hash='b5e3a151f1ba43b2a1cb1563f9f852256b7316dd0aa0a32e86ef75b5bf193df5'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='0bc6bdb3-3919-4aca-bb21-96195de6a6e3', node_type=<ObjectType.TEXT: '1'>, metadata={}, hash='8b3405830444a055e6132d5475cded650f81ab3c87e582e5d76c9c4c3a1c749f')}, text='Two Approaches \nIn reality, creating an ESOP will require a combination of \ntop-down and bottom -up planning Top Down Bottom Up \nDecide the total amount of \nequity to be granted; allocate \nthese shares to employees \nover time Decide the appropriate size of \nindividual equity grants by \nposition; issue these shares as \nemployees are hired', start_char_idx=0, end_char_idx=344, text_template='{metadata_str}\n\n{content}', metadata_template='{key}: {value}', metadata_seperator='\n', index_id='a64f70f9-1ce3-4091-b031-bf5c9a83ef43', obj=None), score=1.5938675), NodeWithScore(node=IndexNode(id_='cf76d79c-2249-44d4-a6d7-acfec1b0e787', embedding=None, metadata={'page_label': '25', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='71a0493f-70ab-4781-8d49-039ba634ce13', node_type=<ObjectType.DOCUMENT: '4'>, metadata={'page_label': '25', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, hash='ed60fd88e84bafe931499ef504a0c5d7a34aa3958c78b0c90feda8cce08ba120'), <NodeRelationship.PREVIOUS: '2'>: RelatedNodeInfo(node_id='f0ef5a77-cb0e-49cf-a11c-af24df5d4fa1', node_type=<ObjectType.TEXT: '1'>, metadata={'page_label': '24', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, hash='83b8bff8a2843beebe6f6d91834d1207dd1ba79dc0313d42cd77f8db5684256e'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='e56159d1-625e-423a-a8d5-03e8531080de', node_type=<ObjectType.TEXT: '1'>, metadata={}, hash='201a91f33f1b4f724c0dab2808d0dc123de931a2dafeaa7bb5ddffab6241b6c5')}, text='Important Takeaways \n•Top-down planning (“the allocation”) \n–Holistically consider what percentage of the company should \nbelong to employees \n–Allocate these shares to an ESOP \n•Bottom -up planning (“the plan”) \n–Specifically consider how much equity each employee should be \nawarded \n–Use this framework for individual equity grants \n•Key Takeaway : Get away from ad hoc equity awards and personal \nnegotiations by standardizing both the amount of equity available to \nemployees and the process by which packages are awarded', start_char_idx=0, end_char_idx=533, text_template='{metadata_str}\n\n{content}', metadata_template='{key}: {value}', metadata_seperator='\n', index_id='cf76d79c-2249-44d4-a6d7-acfec1b0e787', obj=None), score=0.50234926), NodeWithScore(node=IndexNode(id_='4dae098f-9e99-416c-9c22-b6253bbc314e', embedding=None, metadata={'window': 'The defining difference between Silicon Valley companies and almost every other industry in the U.S. is the virtually universal practice among tech companies of distributing meaningful equity (usually in the form of ', 'original_text': 'The defining difference between Silicon Valley companies and almost ', 'page_label': '9', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date', 'window', 'original_text'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date', 'window', 'original_text'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='8e157341-eb5d-40b6-97e7-8b03c320b0c1', node_type=<ObjectType.TEXT: '1'>, metadata={'page_label': '9', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, hash='a03cb60681ad26f28a934ef531e2343f954e682de87890d28fda093ef1e77b1d'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='dce1420c-1e4b-4e64-8f3c-eef8876193a8', node_type=<ObjectType.TEXT: '1'>, metadata={'window': 'The defining difference between Silicon Valley companies and almost every other industry in the U.S. is the virtually universal practice among tech companies of distributing meaningful equity (usually in the form of stock options) to ordinary employees . A Defining Characteristic of Startup Culture ', 'original_text': 'every other industry in the U.S. is the virtually universal practice among '}, hash='364c6dcd73197c86371c578c2ce8486b502fe4c9855fc674398d5284cfe8f90c')}, text='The defining difference between Silicon Valley companies and almost ', start_char_idx=0, end_char_idx=68, text_template='{metadata_str}\n\n{content}', metadata_template='{key}: {value}', metadata_seperator='\n', index_id='8e157341-eb5d-40b6-97e7-8b03c320b0c1', obj=None), score=-4.310295)], metadata={'a64f70f9-1ce3-4091-b031-bf5c9a83ef43': {'page_label': '14', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, 'cf76d79c-2249-44d4-a6d7-acfec1b0e787': {'page_label': '25', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, '4dae098f-9e99-416c-9c22-b6253bbc314e': {'window': 'The defining difference between Silicon Valley companies and almost every other industry in the U.S. is the virtually universal practice among tech companies of distributing meaningful equity (usually in the form of ', 'original_text': 'The defining difference between Silicon Valley companies and almost ', 'page_label': '9', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}})
## Response Generated response=' An Employee Stock Options Plan (ESOP) is a plan that allocates shares of a company that will be granted to employees in the future in the form of stock options. There are two approaches to creating an ESOP: top-down and bottom-up planning. Top-down planning involves deciding the total amount of equity to be granted to employees and allocating these shares to them over time. Bottom-up planning, on the other hand, specifically considers how much equity each employee should be awarded based on their position and uses this framework for individual equity grants. The goal is to get away from ad hoc equity awards and personal negotiations by standardizing both the amount of equity available to employees and the process by which packages are awarded. This practice is widely used in Silicon Valley companies and is a defining characteristic of startup culture.
Method 2 : Setting up a DAG for an advanced RAG workflow
Here we chain together a full RAG pipeline consisting of query rewriting, retrieval, reranking, and response synthesis.
Here we can’t use chain
syntax because certain modules depend on multiple inputs (for instance, response synthesis expects both the retrieved nodes and the original question). Instead we’ll construct a DAG explicitly, through add_modules
and then add_link
.
pipe = QueryPipeline(verbose=True) pipe.add_modules({"prompt_tmpl":prompt_tmpl, "llm":llm, "retriever":retriever_chunk, "reranker":reranker, "query_engine":query_engine_chunk})
We can view the set of input/output keys for each module through module.as_query_component().input_keys
and module.as_query_component().output_keys
.
llm.as_query_component().input_keys,llm.as_query_component().output_keys #### Response (InputKeys(required_keys={'prompt'}, optional_keys=set()), OutputKeys(required_keys={'output'}))
prompt_tmpl.as_query_component().input_keys,prompt_tmpl.as_query_component().output_keys #### Response (InputKeys(required_keys={'question'}, optional_keys=set()), OutputKeys(required_keys={'prompt'}))
retriever_chunk.as_query_component().input_keys,retriever_chunk.as_query_component().output_keys #### Response (InputKeys(required_keys={'input'}, optional_keys=set()), OutputKeys(required_keys={'output'}))
reranker.as_query_component().input_keys,reranker.as_query_component().output_keys ####Response (InputKeys(required_keys={'nodes'}, optional_keys={'query_str'}), OutputKeys(required_keys={'nodes'}))
query_engine_chunk.as_query_component().input_keys,query_engine_chunk.as_query_component().output_keys ####Response (InputKeys(required_keys={'input'}, optional_keys=set()), OutputKeys(required_keys={'output'}))
Since Reranker requires tow inputs hence we have specified dest_key for Reranker
pipe.add_link("prompt_tmpl", "llm") pipe.add_link("llm", "retriever") pipe.add_link("retriever", "reranker",dest_key="nodes") pipe.add_link("llm", "reranker",dest_key="query_str") pipe.add_link("reranker", "query_engine")
Visualize the DAG
## create graph from pyvis.network import Network from IPython.display import HTML, display net = Network(notebook=True, cdn_resources="in_line", directed=True) net.from_nx(pipe.dag) net.save_graph("rag_dag.html") # HTML(filename="rag_dag.html")
response = pipe.run("what is esops ?") ####### Response ######## > Running module prompt_tmpl with input: question: what is esops ? > Running module llm with input: prompt: Please provide a brief answer to the question what is esops ? Llama.generate: prefix-match hit > Running module retriever with input: input: ESOP stands for Employee Stock Ownership Plan. It is a retirement plan that enables employees to own company stocks. The company contributes its own shares to the trust on behalf of the employees, wh... Retrieving with query id None: ESOP stands for Employee Stock Ownership Plan. It is a retirement plan that enables employees to own company stocks. The company contributes its own shares to the trust on behalf of the employees, who become beneficiaries of the trust. ESOPs can also allow employees to purchase company stock at a discounted price or through payroll deductions. The ultimate goal of an ESOP is to align the interests of employees with those of the company's owners and to provide employees with an incentive to increase company value through their work. Retrieved node with id, entering: 3e6e0383-528f-4852-abe3-e5904dea85a9 Retrieving with query id 3e6e0383-528f-4852-abe3-e5904dea85a9: ESOP stands for Employee Stock Ownership Plan. It is a retirement plan that enables employees to own company stocks. The company contributes its own shares to the trust on behalf of the employees, who become beneficiaries of the trust. ESOPs can also allow employees to purchase company stock at a discounted price or through payroll deductions. The ultimate goal of an ESOP is to align the interests of employees with those of the company's owners and to provide employees with an incentive to increase company value through their work. Retrieved node with id, entering: 2311c306-45ef-4c6e-8af3-09d63021dcee Retrieving with query id 2311c306-45ef-4c6e-8af3-09d63021dcee: ESOP stands for Employee Stock Ownership Plan. It is a retirement plan that enables employees to own company stocks. The company contributes its own shares to the trust on behalf of the employees, who become beneficiaries of the trust. ESOPs can also allow employees to purchase company stock at a discounted price or through payroll deductions. The ultimate goal of an ESOP is to align the interests of employees with those of the company's owners and to provide employees with an incentive to increase company value through their work. Retrieved node with id, entering: f08f1387-0c0e-4cb2-8707-438a1d1a5018 Retrieving with query id f08f1387-0c0e-4cb2-8707-438a1d1a5018: ESOP stands for Employee Stock Ownership Plan. It is a retirement plan that enables employees to own company stocks. The company contributes its own shares to the trust on behalf of the employees, who become beneficiaries of the trust. ESOPs can also allow employees to purchase company stock at a discounted price or through payroll deductions. The ultimate goal of an ESOP is to align the interests of employees with those of the company's owners and to provide employees with an incentive to increase company value through their work. Retrieved node with id, entering: 97ae5ee7-16f6-471a-b09f-f101a329700d Retrieving with query id 97ae5ee7-16f6-471a-b09f-f101a329700d: ESOP stands for Employee Stock Ownership Plan. It is a retirement plan that enables employees to own company stocks. The company contributes its own shares to the trust on behalf of the employees, who become beneficiaries of the trust. ESOPs can also allow employees to purchase company stock at a discounted price or through payroll deductions. The ultimate goal of an ESOP is to align the interests of employees with those of the company's owners and to provide employees with an incentive to increase company value through their work. Retrieved node with id, entering: e084f59b-fe5d-4ce0-9b75-b08452642395 Retrieving with query id e084f59b-fe5d-4ce0-9b75-b08452642395: ESOP stands for Employee Stock Ownership Plan. It is a retirement plan that enables employees to own company stocks. The company contributes its own shares to the trust on behalf of the employees, who become beneficiaries of the trust. ESOPs can also allow employees to purchase company stock at a discounted price or through payroll deductions. The ultimate goal of an ESOP is to align the interests of employees with those of the company's owners and to provide employees with an incentive to increase company value through their work. > Running module reranker with input: query_str: ESOP stands for Employee Stock Ownership Plan. It is a retirement plan that enables employees to own company stocks. The company contributes its own shares to the trust on behalf of the employees, wh... nodes: [NodeWithScore(node=IndexNode(id_='3e6e0383-528f-4852-abe3-e5904dea85a9', embedding=None, metadata={'page_label': '4', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path'... > Running module query_engine with input: input: [NodeWithScore(node=IndexNode(id_='e084f59b-fe5d-4ce0-9b75-b08452642395', embedding=None, metadata={'page_label': '5', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path'... Retrieving with query id None: ['Node ID: e084f59b-fe5d-4ce0-9b75-b08452642395\nText: What is an Option? •Why do options have intrinsic value? –A\neffective form of equity ownership –A locked -in price for shares\n•How do startups use options? –To bring in founding team members\nwho are not co -founders –To recruit, compensate and retain early\nemployees –To allow later employees to share in the company’s long\n-term ...\nScore: 2.304\n', 'Node ID: 97ae5ee7-16f6-471a-b09f-f101a329700d\nText: Important Takeaways •Top-down planning (“the allocation”)\n–Holistically consider what percentage of the company should belong\nto employees –Allocate these shares to an ESOP •Bottom -up\nplanning (“the plan”) –Specifically consider how much equity each\nemployee should be awarded –Use this framework for individual\nequity grants •Key...\nScore: -0.228\n', 'Node ID: f08f1387-0c0e-4cb2-8707-438a1d1a5018\nText: Two Approaches In reality, creating an ESOP will require a\ncombination of top-down and bottom -up planning Top Down Bottom Up\nDecide the total amount of equity to be granted; allocate these\nshares to employees over time Decide the appropriate size of\nindividual equity grants by position; issue these shares as\nemployees are hired\nScore: -1.307\n', 'Node ID: 3e6e0383-528f-4852-abe3-e5904dea85a9\nText: What is an ESOP? •An Employee Stock Options Plan (ESOP)\n•An allocation of shares that will be granted to employees in the\nfuture in the form of stock options –How much equity should we set\naside for employees? •A plan for how these options will be\ndistributed: –How many shares will individual employees receive?\n–What terms will...\nScore: -1.509\n', 'Node ID: 2311c306-45ef-4c6e-8af3-09d63021dcee\nText: An option is a right (but not an obligation) to purchase a\nquantity of a company’s stock at a set price for a certain period of\ntime\nScore: -2.569\n'] Retrieved node with id, entering: 68c71220-ddce-44e7-9bc7-48393e4fa124 Retrieving with query id 68c71220-ddce-44e7-9bc7-48393e4fa124: ['Node ID: e084f59b-fe5d-4ce0-9b75-b08452642395\nText: What is an Option? •Why do options have intrinsic value? –A\neffective form of equity ownership –A locked -in price for shares\n•How do startups use options? –To bring in founding team members\nwho are not co -founders –To recruit, compensate and retain early\nemployees –To allow later employees to share in the company’s long\n-term ...\nScore: 2.304\n', 'Node ID: 97ae5ee7-16f6-471a-b09f-f101a329700d\nText: Important Takeaways •Top-down planning (“the allocation”)\n–Holistically consider what percentage of the company should belong\nto employees –Allocate these shares to an ESOP •Bottom -up\nplanning (“the plan”) –Specifically consider how much equity each\nemployee should be awarded –Use this framework for individual\nequity grants •Key...\nScore: -0.228\n', 'Node ID: f08f1387-0c0e-4cb2-8707-438a1d1a5018\nText: Two Approaches In reality, creating an ESOP will require a\ncombination of top-down and bottom -up planning Top Down Bottom Up\nDecide the total amount of equity to be granted; allocate these\nshares to employees over time Decide the appropriate size of\nindividual equity grants by position; issue these shares as\nemployees are hired\nScore: -1.307\n', 'Node ID: 3e6e0383-528f-4852-abe3-e5904dea85a9\nText: What is an ESOP? •An Employee Stock Options Plan (ESOP)\n•An allocation of shares that will be granted to employees in the\nfuture in the form of stock options –How much equity should we set\naside for employees? •A plan for how these options will be\ndistributed: –How many shares will individual employees receive?\n–What terms will...\nScore: -1.509\n', 'Node ID: 2311c306-45ef-4c6e-8af3-09d63021dcee\nText: An option is a right (but not an obligation) to purchase a\nquantity of a company’s stock at a set price for a certain period of\ntime\nScore: -2.569\n'] Retrieved node with id, entering: 3eb15843-ea3b-4a74-8756-1e5f9ad12a80 Retrieving with query id 3eb15843-ea3b-4a74-8756-1e5f9ad12a80: ['Node ID: e084f59b-fe5d-4ce0-9b75-b08452642395\nText: What is an Option? •Why do options have intrinsic value? –A\neffective form of equity ownership –A locked -in price for shares\n•How do startups use options? –To bring in founding team members\nwho are not co -founders –To recruit, compensate and retain early\nemployees –To allow later employees to share in the company’s long\n-term ...\nScore: 2.304\n', 'Node ID: 97ae5ee7-16f6-471a-b09f-f101a329700d\nText: Important Takeaways •Top-down planning (“the allocation”)\n–Holistically consider what percentage of the company should belong\nto employees –Allocate these shares to an ESOP •Bottom -up\nplanning (“the plan”) –Specifically consider how much equity each\nemployee should be awarded –Use this framework for individual\nequity grants •Key...\nScore: -0.228\n', 'Node ID: f08f1387-0c0e-4cb2-8707-438a1d1a5018\nText: Two Approaches In reality, creating an ESOP will require a\ncombination of top-down and bottom -up planning Top Down Bottom Up\nDecide the total amount of equity to be granted; allocate these\nshares to employees over time Decide the appropriate size of\nindividual equity grants by position; issue these shares as\nemployees are hired\nScore: -1.307\n', 'Node ID: 3e6e0383-528f-4852-abe3-e5904dea85a9\nText: What is an ESOP? •An Employee Stock Options Plan (ESOP)\n•An allocation of shares that will be granted to employees in the\nfuture in the form of stock options –How much equity should we set\naside for employees? •A plan for how these options will be\ndistributed: –How many shares will individual employees receive?\n–What terms will...\nScore: -1.509\n', 'Node ID: 2311c306-45ef-4c6e-8af3-09d63021dcee\nText: An option is a right (but not an obligation) to purchase a\nquantity of a company’s stock at a set price for a certain period of\ntime\nScore: -2.569\n'] Retrieved node with id, entering: 44486da8-3b12-4667-8e8f-4dc6be4494cd Retrieving with query id 44486da8-3b12-4667-8e8f-4dc6be4494cd: ['Node ID: e084f59b-fe5d-4ce0-9b75-b08452642395\nText: What is an Option? •Why do options have intrinsic value? –A\neffective form of equity ownership –A locked -in price for shares\n•How do startups use options? –To bring in founding team members\nwho are not co -founders –To recruit, compensate and retain early\nemployees –To allow later employees to share in the company’s long\n-term ...\nScore: 2.304\n', 'Node ID: 97ae5ee7-16f6-471a-b09f-f101a329700d\nText: Important Takeaways •Top-down planning (“the allocation”)\n–Holistically consider what percentage of the company should belong\nto employees –Allocate these shares to an ESOP •Bottom -up\nplanning (“the plan”) –Specifically consider how much equity each\nemployee should be awarded –Use this framework for individual\nequity grants •Key...\nScore: -0.228\n', 'Node ID: f08f1387-0c0e-4cb2-8707-438a1d1a5018\nText: Two Approaches In reality, creating an ESOP will require a\ncombination of top-down and bottom -up planning Top Down Bottom Up\nDecide the total amount of equity to be granted; allocate these\nshares to employees over time Decide the appropriate size of\nindividual equity grants by position; issue these shares as\nemployees are hired\nScore: -1.307\n', 'Node ID: 3e6e0383-528f-4852-abe3-e5904dea85a9\nText: What is an ESOP? •An Employee Stock Options Plan (ESOP)\n•An allocation of shares that will be granted to employees in the\nfuture in the form of stock options –How much equity should we set\naside for employees? •A plan for how these options will be\ndistributed: –How many shares will individual employees receive?\n–What terms will...\nScore: -1.509\n', 'Node ID: 2311c306-45ef-4c6e-8af3-09d63021dcee\nText: An option is a right (but not an obligation) to purchase a\nquantity of a company’s stock at a set price for a certain period of\ntime\nScore: -2.569\n'] Retrieved node with id, entering: 28ed05bb-863c-4a26-8c8b-2705428d5d18 Retrieving with query id 28ed05bb-863c-4a26-8c8b-2705428d5d18: ['Node ID: e084f59b-fe5d-4ce0-9b75-b08452642395\nText: What is an Option? •Why do options have intrinsic value? –A\neffective form of equity ownership –A locked -in price for shares\n•How do startups use options? –To bring in founding team members\nwho are not co -founders –To recruit, compensate and retain early\nemployees –To allow later employees to share in the company’s long\n-term ...\nScore: 2.304\n', 'Node ID: 97ae5ee7-16f6-471a-b09f-f101a329700d\nText: Important Takeaways •Top-down planning (“the allocation”)\n–Holistically consider what percentage of the company should belong\nto employees –Allocate these shares to an ESOP •Bottom -up\nplanning (“the plan”) –Specifically consider how much equity each\nemployee should be awarded –Use this framework for individual\nequity grants •Key...\nScore: -0.228\n', 'Node ID: f08f1387-0c0e-4cb2-8707-438a1d1a5018\nText: Two Approaches In reality, creating an ESOP will require a\ncombination of top-down and bottom -up planning Top Down Bottom Up\nDecide the total amount of equity to be granted; allocate these\nshares to employees over time Decide the appropriate size of\nindividual equity grants by position; issue these shares as\nemployees are hired\nScore: -1.307\n', 'Node ID: 3e6e0383-528f-4852-abe3-e5904dea85a9\nText: What is an ESOP? •An Employee Stock Options Plan (ESOP)\n•An allocation of shares that will be granted to employees in the\nfuture in the form of stock options –How much equity should we set\naside for employees? •A plan for how these options will be\ndistributed: –How many shares will individual employees receive?\n–What terms will...\nScore: -1.509\n', 'Node ID: 2311c306-45ef-4c6e-8af3-09d63021dcee\nText: An option is a right (but not an obligation) to purchase a\nquantity of a company’s stock at a set price for a certain period of\ntime\nScore: -2.569\n'] Llama.generate: prefix-match hit
print(str(response)) ####### Response ####### An option is a right, but not an obligation, to purchase a quantity of a company's stock at a set price for a certain period of time. Startups use options as an effective form of equity ownership and a locked-in price for shares to bring in founding team members who are not co-founders, recruit, compensate, and retain early employees, and allow later employees to share in the company's long-term success. Creating an ESOP requires a combination of top-down and bottom-up planning. Top-down planning involves deciding the total amount of equity to be granted and allocating these shares to employees over time. Bottom-up planning involves deciding the appropriate size of individual equity grants by position and issuing these shares as employees are hired. The ESOP is an allocation of shares that will be granted to employees in the future in the form of stock options. The amount of equity that should be set aside for employees and the terms of the options distribution are important considerations in an ESOP.
Setup DAG for Advanced RAG workflow without Query rewriting
from llama_index.query_pipeline import InputComponent inputs = InputComponent() pipe_1 = QueryPipeline(verbose=True) pipe_1.add_modules({"input":inputs, "retriever":retriever_chunk, "query_engine":query_engine_chunk})
pipe_1.add_link("input", "retriever") pipe_1.add_link("input", "query_engine") pipe_1.add_link("retriever", "query_engine")
Visualize DAG
output = pipe_1.run(input="what is esops ?") ###### Response > Running module input with input: input: what is esops ? > Running module retriever with input: input: what is esops ? Retrieving with query id None: what is esops ? Retrieved node with id, entering: 82dcddb6-55e1-43fc-b1c2-0460460bae61 Retrieving with query id 82dcddb6-55e1-43fc-b1c2-0460460bae61: what is esops ? Retrieved node with id, entering: 6c5ecaf9-09be-4712-a0e9-4807cbcae1bd Retrieving with query id 6c5ecaf9-09be-4712-a0e9-4807cbcae1bd: what is esops ? Retrieved node with id, entering: b0e7bf68-fc08-4667-99fb-a638d170fafd Retrieving with query id b0e7bf68-fc08-4667-99fb-a638d170fafd: what is esops ? > Running module query_engine with input: input: [NodeWithScore(node=IndexNode(id_='82dcddb6-55e1-43fc-b1c2-0460460bae61', embedding=None, metadata={'page_label': '4', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path'... Llama.generate: prefix-match hit Generated queries: 1. "Employee Stock Options Plan (ESOP): How is equity allocated to employees?" 2. "Determining the number of shares for individual employees in an ESOP" 3. "ESOP distribution terms: How are stock options valued over multiple years?" Llama.generate: prefix-match hit
print(str(output)) #### Response An Employee Stock Options Plan (ESOP) is a plan that allocates shares that will be granted to employees in the future in the form of stock options. The company needs to determine how much equity to set aside for employees and create a plan for how these options will be distributed. The distribution plan includes determining how many shares individual employees will receive and what terms will govern these grants
Query Pipeline 2 using Hybrid Retriever, LongContextReorder and Reranker
inputs = InputComponent() pipe_2 = QueryPipeline(verbose=True) pipe_2.add_modules({"input":inputs, "retriever":hybrid_retriever, "query_engine":query_engine_chunk}) # pipe_2.add_link("input", "retriever") pipe_2.add_link("retriever", "query_engine")
Visualize DAG
response = pipe_2.run(input="what is esops ?") ##### Response > Running module input with input: input: what is esops ? > Running module retriever with input: input: what is esops ? Llama.generate: prefix-match hit Generated queries: 1. "What is the meaning of ESOPs in business?" 2. "Explanation of Employee Stock Ownership Plans (ESOPs)" 3. "How do Employee Stock Ownership Plans (ESOPs) work?" > Running module query_engine with input: input: [NodeWithScore(node=IndexNode(id_='3e6e0383-528f-4852-abe3-e5904dea85a9', embedding=None, metadata={'page_label': '4', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path'... Llama.generate: prefix-match hit Generated queries: 1. "How does an Employee Stock Options Plan (ESOP) work for companies?" 2. "What is the process for distributing shares in an ESOP?" 3. "How is the number of shares determined for individual employees in an ESOP?" Llama.generate: prefix-match hit
print(str(response)) ##### Response An Employee Stock Options Plan (ESOP) is a plan through which a company sets aside a certain allocation of shares that will be granted to employees in the future in the form of stock options. The company determines how much equity to set aside for non-founder employees and creates a schedule for how this equity will be distributed over time. The number of shares that individual employees will receive is part of the plan for distributing
Implementing DAG for advanced QueryPipelines using Dense Retriever , Sparse Retriever, Longcontext Reorder, Reranker components Individually
# define query pipeline pipe_5 = QueryPipeline(verbose=True) pipe_5.add_modules( { "input": inputs, "retriever": vector_retriever_chunk, "bm25": bm25_retriever, "longcontext": lim_reorder, "reranker": reranker, "summarizer": summarizer, }
pipe_5.add_link("input","retriever") pipe_5.add_link("input","bm25") pipe_5.add_link("retriever","longcontext",dest_key="nodes") pipe_5.add_link("bm25","longcontext",dest_key="nodes") pipe_5.add_link("input","longcontext",dest_key='query_str') pipe_5.add_link("longcontext","reranker",dest_key="nodes") pipe_5.add_link("input","reranker",dest_key="query_str") pipe_5.add_link("reranker","summarizer",dest_key="nodes") pipe_5.add_link("input","summarizer",dest_key="query_str")
Visualize the DAG
output = pipe_5.run(question="What is the purpose of using options by startups?") ##### Response Log > Running module input with input: question: What is the purpose of using options by startups? > Running module retriever with input: input: What is the purpose of using options by startups? > Running module bm25 with input: input: What is the purpose of using options by startups? > Running module longcontext with input: query_str: What is the purpose of using options by startups? nodes: [NodeWithScore(node=IndexNode(id_='673ff081-6622-49f3-ab23-c76ceb8792ef', embedding=None, metadata={'window': '•Why do options have intrinsic value? –A effective form of equity ownership –A locked... > Running module reranker with input: query_str: What is the purpose of using options by startups? nodes: [NodeWithScore(node=IndexNode(id_='673ff081-6622-49f3-ab23-c76ceb8792ef', embedding=None, metadata={'window': '•Why do options have intrinsic value? –A effective form of equity ownership –A locked... > Running module summarizer with input: query_str: What is the purpose of using options by startups? nodes: [NodeWithScore(node=IndexNode(id_='673ff081-6622-49f3-ab23-c76ceb8792ef', embedding=None, metadata={'window': '•Why do options have intrinsic value? –A effective form of equity ownership –A locked... Llama.generate: prefix-match
print(str(output)) ##### Response Based on the provided information, startups use options as a way to align employees with the company's goal of achieving a "big exit." Options serve as incentives for employees in high-risk/high-reward enterprises where traditional compensation packages may not be feasible.
output.metadata ###### Response { '673ff081-6622-49f3-ab23-c76ceb8792ef': {'window': '•Why do options have intrinsic value? –A effective form of equity ownership –A locked -in price for shares •How do startups use options? –To bring in founding team members who are not co -founders ', 'original_text': '•How do startups use options? ', 'page_label': '5', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, 'a7026325-5afd-484c-aea2-35a06e7c954b': {'window': '–As high -risk/high -reward enterprises, startups use options to align employee compensation with the risk -prone mentality of the business –Startups seeking to achieve a “big exit” use options to align all employees to drive toward this desired outcome', 'original_text': '–Startups seeking to achieve a “big exit” use options to align all ', 'page_label': '9', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, '42dd2c12-4c82-44fc-b002-26d5b57d9f55': {'window': 'Steven Johnson, Technology Writer •Startups are a unique case . Unlike at larger corporations, employee ownership is an essential element of startup communities and culture –As high -risk/high -reward enterprises, startups use options to align employee compensation with the risk -prone mentality of the business ', 'original_text': '–As high -risk/high -reward enterprises, startups use options to align ', 'page_label': '9', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, '0d016eea-f0c5-4995-b704-7167e6c347f7': {'window': "to offer options packages to compete for top talent with other venture -backed companies –When operating budgets are tight, competitive compensation packages may not be possible; options can be used to incentivize employees instead of cash I can't think of a term sheet that we have issued that didn't have a ", 'original_text': 'packages may not be possible; options can be used to incentivize ', 'page_label': '10', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'}, 'c06fa563-1a8c-4565-951b-93d45f24d934': {'window': 'early employees –To allow later employees to share in the company’s long -term upside Terminology: This presentation uses “options” generally to refer to several types of securities that are often issued to startup ', 'original_text': 'This presentation uses “options” ', 'page_label': '5', 'file_name': 'Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_path': '/content/Data/esops.pdf/Employee-Stock-Option-Plans-ESOP-Best-Practices-2.pdf', 'file_type': 'application/pdf', 'file_size': 724217, 'creation_date': '2024-02-04', 'last_modified_date': '2018-08-29', 'last_accessed_date': '2024-02-04'} }
Conclusion
Here we have explored QueryPipelines and the different approaches to implement it.