In this notebook we will look into
RouterQueryEngine
to route the user queries to one of the available query engine tools. These tools can be different indices/ query engine on same documents/ different documents.
Installation
%pip install llama-index
%pip install llama-index-llms-juglow
%pip install llama-index-embeddings-huggingface
Set Logging
logger = logging.getLogger()
logger.setLevel(logging.INFO) # Set logger level to INFO
Clear out any existing handlers
logger.handlers = []
Set up the StreamHandler to output to sys.stdout (Colab's output)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO) # Set handler level to INFO
Add the handler to the logger
logger.addHandler(handler)
from IPython.display import HTML, display
Set Haijun API Key
ing-bottom:12px;tab-size:4">
!mkdir -p 'data/paul_graham/'
!wget 'https://raw.githubusercontent.com/jerryjliu/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'
--2024-03-08 07:04:27-- https://raw.githubusercontent.com/jerryjliu/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.108.133, ... Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 75042 (73K) [text/plain] Saving to: ‘data/paul_graham/paul_graham_essay.txt’ data/paul_graham/pa 100%[===================>] 73.28K --.-KB/s in 0.002s 2024-03-08 07:04:27 (28.6 MB/s) - ‘data/paul_graham/paul_graham_essay.txt’ saved [75042/75042]
Load Document
response = query_engine.query("What did Paul Graham do growing up?")
HTTP Request: POST https://haijun.my.id/v1/messages "HTTP/1.1 200 OK" Selecting query engine 1: The question asks about specific details from Paul Graham's life, which would likely be found in the original essay. A summary of the essay may not include all the relevant details about what he did growing up.. HTTP Request: POST https://haijun.my.id/v1/messages "HTTP/1.1 200 OK"
display(HTML(f'
{response.response}
'))