Find answers from the community

Updated 3 months ago

Loading indexes

Okay so I'm only 2 weeks into coding for python and applying knowledge from other languages so I just need to make sure I am on the right path. I have a folder with a collection of indexes. These are the used for build a graph, etc. Currently the graph builds as expected and outputs a json file but querying it fails. So I am working backwards from there.

Is this a valid way to load in multiple indexes at once? The array passed into it is a collection of document names.

def load_all_indexes(index_files):
indexes = []
print(index_files)
for index_file in index_files:
index = GPTSimpleVectorIndex.load_from_disk(index_file, service_context=service_context)
indexes.append(index)
return indexes
L
E
13 comments
Looks fine to me πŸ€”

Whats the error when querying?
@Logan M When running a query to the graph with the mode "recursive" augment. I get an error that the augment "mode" is unexpected.

My build graph function looks like this:

def build_and_save_graph(indexes, summaries):
global graph
graph = ComposableGraph.from_indices(
GPTTreeIndex,
indexes,
index_summaries=summaries
)




And my query looks like this:


def query_index(query_text):
global graph, service_context
"""Query the global index."""
response = graph.query(
str(query_text),
mode="recursive",
query_configs=query_configs,
service_context=service_context
)

return response
I assumed I must be loading in things incorrectly. Or at least this was my first troubleshooting step.

My specific error is:

TypeError: ComposableGraph.query() got an unexpected keyword argument 'mode'
Oh, I don't think the mode argument is needed here! You can remove it πŸ‘
Alright give me a second
@Logan M So there is definitely progress, it thinks for a bit and spits out something I assume but I guess I am incorrectly processing it.

Here is my error:

"similarity": round(x.similarity, 2),
TypeError: type NoneType doesn't define round method

Here is the code:

response_json = {
"text": str(response),
"sources": [{"text": str(x.source_text),
"similarity": round(x.similarity, 2),
"doc_id": str(x.doc_id),
"start": x.node_info['start'],
"end": x.node_info['end']
} for x in response.source_nodes]
}
return make_response(jsonify(response_json)), 200


This was pulled from the original flask example in the docs where we load a simple index. I assume I can't pull sources anymore and that's my issue?
Ah, I need to update that tutorial! Whoops lol

Try x.score instead of x.similarity
@Logan M That doesn't seem to have made a difference in my case. But I think that the variable "x" which represents the sources is likely empty. Where is this generated considering the query of the graph only returns the answer?
The code should work even if response.source_nodes is empty, since otherwise it would be an empty list πŸ€”

But true, I don't think I tested this on a graph lol. What happens if you comment the sources key for now?
@Logan M The call works. The whole front-end breaks but that's not a concern right now.

So I assume it's the empty list that is the issue. Is there a way I can debug the response.source_nodes?
(To avoid breaking the frintend, you could try putting in dummy values)

I'm not sure actually. I think something about using a graph is not returning source nodes properly πŸ€” πŸ™ƒ
@Logan M Well, I certainly appreciate your help so far! I might spend some time this week stripping it back and just doing calls directly to troubleshoot.
Sounds good to me! Good luck! πŸ’ͺ🫑
Add a reply
Sign up and join the conversation on Discord