Skip to content

Commit

Permalink
fix: update non local mode in LightRAG
Browse files Browse the repository at this point in the history
  • Loading branch information
taprosoft committed Dec 17, 2024
1 parent 26abbcb commit f9d6650
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 38 deletions.
2 changes: 1 addition & 1 deletion flowsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@

if USE_NANO_GRAPHRAG:
GRAPHRAG_INDEX_TYPES.append("ktem.index.file.graph.NanoGraphRAGIndex")
elif USE_LIGHTRAG:
if USE_LIGHTRAG:
GRAPHRAG_INDEX_TYPES.append("ktem.index.file.graph.LightRAGIndex")

KH_INDEX_TYPES = [
Expand Down
5 changes: 5 additions & 0 deletions libs/ktem/ktem/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ mark {
right: 15px;
}

/* prevent overflow of html info panel */
#html-info-panel {
overflow-x: auto !important;
}

#chat-expand-button {
position: absolute;
top: 6px;
Expand Down
54 changes: 37 additions & 17 deletions libs/ktem/ktem/index/file/graph/lightrag_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def get_user_settings(cls) -> dict:
"search_type": {
"name": "Search type",
"value": "local",
"choices": ["local", "global", "hybrid", "naive"],
"choices": ["local", "global", "hybrid"],
"component": "dropdown",
"info": "Whether to use local or global search in the graph.",
}
Expand Down Expand Up @@ -425,20 +425,40 @@ def run(
return []

graphrag_func, query_params = self._build_graph_search()
entities, relationships, sources = asyncio.run(
lightrag_build_local_query_context(graphrag_func, text, query_params)
)

documents = self.format_context_records(entities, relationships, sources)
plot = self.plot_graph(relationships)

return documents + [
RetrievedDocument(
text="",
metadata={
"file_name": "GraphRAG",
"type": "plot",
"data": plot,
},
),
]
# only local mode support graph visualization
if query_params.mode == "local":
entities, relationships, sources = asyncio.run(
lightrag_build_local_query_context(graphrag_func, text, query_params)
)
documents = self.format_context_records(entities, relationships, sources)
plot = self.plot_graph(relationships)
documents += [
RetrievedDocument(
text="",
metadata={
"file_name": "GraphRAG",
"type": "plot",
"data": plot,
},
),
]
else:
context = graphrag_func.query(text, query_params)

# account for missing ``` for closing code block
context += "\n```"

documents = [
RetrievedDocument(
text=context,
metadata={
"file_name": "GraphRAG {} Search".format(
query_params.mode.capitalize()
),
"type": "table",
},
)
]

return documents
59 changes: 40 additions & 19 deletions libs/ktem/ktem/index/file/graph/nano_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def get_user_settings(cls) -> dict:
"search_type": {
"name": "Search type",
"value": "local",
"choices": ["local", "global", "naive"],
"choices": ["local", "global"],
"component": "dropdown",
"info": "Whether to use local or global search in the graph.",
}
Expand Down Expand Up @@ -428,22 +428,43 @@ def run(
return []

graphrag_func, query_params = self._build_graph_search()
entities, relationships, reports, sources = asyncio.run(
nano_graph_rag_build_local_query_context(graphrag_func, text, query_params)
)

documents = self.format_context_records(
entities, relationships, reports, sources
)
plot = self.plot_graph(relationships)

return documents + [
RetrievedDocument(
text="",
metadata={
"file_name": "GraphRAG",
"type": "plot",
"data": plot,
},
),
]
# only local mode support graph visualization
if query_params.mode == "local":
entities, relationships, reports, sources = asyncio.run(
nano_graph_rag_build_local_query_context(
graphrag_func, text, query_params
)
)

documents = self.format_context_records(
entities, relationships, reports, sources
)
plot = self.plot_graph(relationships)

documents += [
RetrievedDocument(
text="",
metadata={
"file_name": "GraphRAG",
"type": "plot",
"data": plot,
},
),
]
else:
context = graphrag_func.query(text, query_params)

documents = [
RetrievedDocument(
text=context,
metadata={
"file_name": "GraphRAG {} Search".format(
query_params.mode.capitalize()
),
"type": "table",
},
)
]

return documents
8 changes: 7 additions & 1 deletion libs/ktem/ktem/utils/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ def collapsible(header, content, open: bool = False) -> str:
def table(text: str) -> str:
"""Render table from markdown format into HTML"""
text = replace_mardown_header(text)
return markdown.markdown(text, extensions=["markdown.extensions.tables"])
return markdown.markdown(
text,
extensions=[
"markdown.extensions.tables",
"markdown.extensions.fenced_code",
],
)

@staticmethod
def preview(
Expand Down

0 comments on commit f9d6650

Please sign in to comment.