|
19 | 19 | from llama_index.node_parser.extractors import (
|
20 | 20 | KeywordExtractor,
|
21 | 21 | MetadataExtractor,
|
22 |
| - # MetadataFeatureExtractor, |
23 | 22 | QuestionsAnsweredExtractor,
|
24 | 23 | SummaryExtractor,
|
25 | 24 | TitleExtractor,
|
@@ -105,7 +104,7 @@ def _get_node_parser() -> SimpleNodeParser:
|
105 | 104 |
|
106 | 105 | node_parser = (
|
107 | 106 | SimpleNodeParser.from_defaults( # SimpleNodeParser is the default when calling ServiceContext.from_defaults()
|
108 |
| - metadata_extractor=metadata_extractor, # adds extracted metatdata as extra_info |
| 107 | + metadata_extractor=metadata_extractor, # adds extracted metadata as extra_info |
109 | 108 | )
|
110 | 109 | )
|
111 | 110 |
|
@@ -138,29 +137,41 @@ def run_ask(input_: str, history: str, space: SpaceKey = None, spaces: list[Spac
|
138 | 137 | # With additional spaces likely to be combining a number of shared spaces.
|
139 | 138 | indices = []
|
140 | 139 | summaries = []
|
| 140 | + output = _default_response() |
141 | 141 | all_spaces = spaces + ([space] if space else [])
|
142 | 142 | for s_ in all_spaces:
|
143 | 143 | try:
|
144 | 144 | index_ = _load_index_from_storage(s_)
|
145 | 145 | summary_ = index_.as_query_engine().query(
|
146 | 146 | "What is the summary of all the documents?"
|
147 | 147 | ) # note: we might not need to do this any longer because summary is added as node metadata.
|
148 |
| - indices.append(index_) |
149 |
| - |
150 |
| - summaries.append(summary_.response) |
| 148 | + if summary_ and summary_.response is not None: |
| 149 | + indices.append(index_) |
| 150 | + summaries.append(summary_.response) |
| 151 | + else: |
| 152 | + log.warning("The summary generated for Space '%s' was empty so skipping from the Graph index.", s_) |
| 153 | + continue |
151 | 154 | except Exception as e:
|
152 | 155 | log.warning(
|
153 |
| - "Index for space '%s' failed to load. Maybe the index isn't created yet. Error message: %s", s_, e |
| 156 | + "Index for space '%s' failed to load, skipping. Maybe the index isn't created yet. Error message: %s", |
| 157 | + s_, |
| 158 | + e, |
154 | 159 | )
|
155 | 160 | continue
|
156 | 161 |
|
157 | 162 | log.debug("number summaries: %s", len(summaries))
|
158 |
| - graph = ComposableGraph.from_indices( |
159 |
| - GPTListIndex, indices, index_summaries=summaries, service_context=_get_service_context() |
160 |
| - ) |
161 |
| - output = graph.as_query_engine().query(PROMPT_QUESTION.format(history=history, input=input_)) |
162 |
| - |
163 |
| - log.debug("(Ask combined spaces %s) Q: %s, A: %s", all_spaces, input_, output) |
| 163 | + try: |
| 164 | + graph = ComposableGraph.from_indices( |
| 165 | + GPTListIndex, indices, index_summaries=summaries, service_context=_get_service_context() |
| 166 | + ) |
| 167 | + output = graph.as_query_engine().query(PROMPT_QUESTION.format(history=history, input=input_)) |
| 168 | + |
| 169 | + log.debug("(Ask combined spaces %s) Q: %s, A: %s", all_spaces, input_, output) |
| 170 | + except Exception as e: |
| 171 | + log.error( |
| 172 | + "Failed to create ComposableGraph. Maybe there was an issue with one of the Space indexes. Error message: %s", |
| 173 | + e, |
| 174 | + ) |
164 | 175 | else:
|
165 | 176 | # No additional spaces i.e. likely to be against a user's documents in their personal space.
|
166 | 177 | if space is None:
|
|
0 commit comments