Find answers from the community

Updated 2 years ago

Token usage

how i can extract the llama_index.token_counter.token_counter form a index.query ?? i need to know how mutch i consume of them in every query
L
C
16 comments
Try
index.service_context.llm_predictor._last_token_usage

And also
index.service_context.embed_model._last_token_usage
ojjjo ... let me try it jejejeje
it works perfects ....thanks ...
i was reading the documentation and it said that i can adjust the output of the query ... with a cain of template ... but i can not find a example ... my idea is that as the result of the query i recover the response of the query but also a document related to the response ... do you know if that its possible ?
You can get the nodes used to create the response like this

response = index.query(...)
print(response.source_nodes)

However, if you want to get the name of the document it came from, there's some extra setup when creating the document objects

Something like this
Plain Text
for doc in documents:
    doc.extra_info = {"name": "name"}


Then that will show up in the source nodes
mmmmm ok ... let me test that ...
mmm not work as spected ....
works...but...i use a GPTListIndex...so when i query them...the result contains all source documents...perhaps because i use mode="recursive"...what do you think?
Ah, a list index will always check each node.

If you only want to check the closest matching node(s), look into using GPTSimpleVectorIndex maybe?
yes ... but the think is that i requere a couple of documents to index and query them ... all of them have information that it is relevant to the knowledge and my idea is that when respond .. it show to the user the documento where the information is it ...

other way is make a index of documents in a new document that way part of the answer contain a link or a datasource of the documento that query before
documento = document πŸ˜› (sorry)
Haha no worries, that makes sense!

You could set the top_k in vector index to reduce the search space compared to a list index.

response = index.query(..., similarity_top_k=5)
mmm not work .. always shows the same sources_nodes ... let me read about it ... and let you know if i find something ... thanks by the way !!!
Sounds good, good luck! πŸ’ͺ
Add a reply
Sign up and join the conversation on Discord