meshrag 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. lightrag/__init__.py +7 -0
  2. lightrag/api/__init__.py +1 -0
  3. lightrag/api/auth.py +109 -0
  4. lightrag/api/config.py +589 -0
  5. lightrag/api/external_kb_client.py +268 -0
  6. lightrag/api/gunicorn_config.py +162 -0
  7. lightrag/api/lightrag_server.py +1691 -0
  8. lightrag/api/llm_factory.py +307 -0
  9. lightrag/api/rag_manager.py +2017 -0
  10. lightrag/api/registry.py +209 -0
  11. lightrag/api/routers/__init__.py +12 -0
  12. lightrag/api/routers/document_routes.py +4433 -0
  13. lightrag/api/routers/graph_routes.py +737 -0
  14. lightrag/api/routers/ollama_api.py +778 -0
  15. lightrag/api/routers/query_routes.py +1645 -0
  16. lightrag/api/routers/registry_routes.py +250 -0
  17. lightrag/api/run_with_gunicorn.py +282 -0
  18. lightrag/api/static/swagger-ui/favicon-32x32.png +0 -0
  19. lightrag/api/static/swagger-ui/swagger-ui-bundle.js +2 -0
  20. lightrag/api/static/swagger-ui/swagger-ui.css +3 -0
  21. lightrag/api/utils_api.py +438 -0
  22. lightrag/api/webui/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  23. lightrag/api/webui/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  24. lightrag/api/webui/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  25. lightrag/api/webui/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  26. lightrag/api/webui/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  27. lightrag/api/webui/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  28. lightrag/api/webui/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  29. lightrag/api/webui/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  30. lightrag/api/webui/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  31. lightrag/api/webui/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  32. lightrag/api/webui/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  33. lightrag/api/webui/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  34. lightrag/api/webui/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  35. lightrag/api/webui/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  36. lightrag/api/webui/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  37. lightrag/api/webui/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  38. lightrag/api/webui/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  39. lightrag/api/webui/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  40. lightrag/api/webui/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  41. lightrag/api/webui/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  42. lightrag/api/webui/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  43. lightrag/api/webui/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  44. lightrag/api/webui/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  45. lightrag/api/webui/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  46. lightrag/api/webui/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  47. lightrag/api/webui/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  48. lightrag/api/webui/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  49. lightrag/api/webui/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  50. lightrag/api/webui/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  51. lightrag/api/webui/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  52. lightrag/api/webui/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  53. lightrag/api/webui/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  54. lightrag/api/webui/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  55. lightrag/api/webui/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  56. lightrag/api/webui/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  57. lightrag/api/webui/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  58. lightrag/api/webui/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  59. lightrag/api/webui/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  60. lightrag/api/webui/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  61. lightrag/api/webui/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  62. lightrag/api/webui/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  63. lightrag/api/webui/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  64. lightrag/api/webui/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  65. lightrag/api/webui/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  66. lightrag/api/webui/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  67. lightrag/api/webui/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  68. lightrag/api/webui/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  69. lightrag/api/webui/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  70. lightrag/api/webui/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  71. lightrag/api/webui/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  72. lightrag/api/webui/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  73. lightrag/api/webui/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  74. lightrag/api/webui/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  75. lightrag/api/webui/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  76. lightrag/api/webui/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  77. lightrag/api/webui/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  78. lightrag/api/webui/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  79. lightrag/api/webui/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  80. lightrag/api/webui/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  81. lightrag/api/webui/assets/arc-DYhJXBOL.js +1 -0
  82. lightrag/api/webui/assets/architectureDiagram-VXUJARFQ-D9NMPF4e.js +36 -0
  83. lightrag/api/webui/assets/blockDiagram-VD42YOAC-CxEq2npg.js +122 -0
  84. lightrag/api/webui/assets/c4Diagram-YG6GDRKO-Lf93PvOJ.js +10 -0
  85. lightrag/api/webui/assets/channel-BXtDqxR_.js +1 -0
  86. lightrag/api/webui/assets/chunk-4BX2VUAB-CqSR1aut.js +1 -0
  87. lightrag/api/webui/assets/chunk-55IACEB6-BTQ9UTO6.js +1 -0
  88. lightrag/api/webui/assets/chunk-B4BG7PRW-Cn5DVGI2.js +165 -0
  89. lightrag/api/webui/assets/chunk-DI55MBZ5-DxhGfynN.js +220 -0
  90. lightrag/api/webui/assets/chunk-FMBD7UC4-Dn-ygM4b.js +15 -0
  91. lightrag/api/webui/assets/chunk-QN33PNHL-DTW-5i10.js +1 -0
  92. lightrag/api/webui/assets/chunk-QZHKN3VN-Du90MEcU.js +1 -0
  93. lightrag/api/webui/assets/chunk-TZMSLE5B-COJpgEFo.js +1 -0
  94. lightrag/api/webui/assets/classDiagram-2ON5EDUG-Bj029qmo.js +1 -0
  95. lightrag/api/webui/assets/classDiagram-v2-WZHVMYZB-Bj029qmo.js +1 -0
  96. lightrag/api/webui/assets/clone-hXTrbV6b.js +1 -0
  97. lightrag/api/webui/assets/cose-bilkent-S5V4N54A-ztzrGaGR.js +1 -0
  98. lightrag/api/webui/assets/cytoscape.esm-5J0xJHOV.js +321 -0
  99. lightrag/api/webui/assets/dagre-6UL2VRFP-BixxvexV.js +4 -0
  100. lightrag/api/webui/assets/defaultLocale-C4B-KCzX.js +1 -0
  101. lightrag/api/webui/assets/diagram-PSM6KHXK-DdMjU-2l.js +24 -0
  102. lightrag/api/webui/assets/diagram-QEK2KX5R--bW-kATO.js +43 -0
  103. lightrag/api/webui/assets/diagram-S2PKOQOG-Dp_demLf.js +24 -0
  104. lightrag/api/webui/assets/erDiagram-Q2GNP2WA-plX8IRia.js +60 -0
  105. lightrag/api/webui/assets/flowDiagram-NV44I4VS-DtISCBNJ.js +162 -0
  106. lightrag/api/webui/assets/ganttDiagram-JELNMOA3-DkI0SmS_.js +267 -0
  107. lightrag/api/webui/assets/gitGraphDiagram-V2S2FVAM-CO-hc35z.js +65 -0
  108. lightrag/api/webui/assets/graph-CPCuV3C_.js +1 -0
  109. lightrag/api/webui/assets/index-C0Ra6R2k.js +3 -0
  110. lightrag/api/webui/assets/index-YTWDz8XI.css +1 -0
  111. lightrag/api/webui/assets/index-eBABlMd0.js +1764 -0
  112. lightrag/api/webui/assets/infoDiagram-HS3SLOUP-xCmix8cZ.js +2 -0
  113. lightrag/api/webui/assets/init-Gi6I4Gst.js +1 -0
  114. lightrag/api/webui/assets/journeyDiagram-XKPGCS4Q-4ZzY1szP.js +139 -0
  115. lightrag/api/webui/assets/kanban-definition-3W4ZIXB7-Df4v75SF.js +89 -0
  116. lightrag/api/webui/assets/layout-DAeEobxq.js +1 -0
  117. lightrag/api/webui/assets/linear-DHPlqM1b.js +1 -0
  118. lightrag/api/webui/assets/mindmap-definition-VGOIOE7T-DfHrkp2z.js +68 -0
  119. lightrag/api/webui/assets/ordinal-BENe2yWM.js +1 -0
  120. lightrag/api/webui/assets/pieDiagram-ADFJNKIX-1k4st0T2.js +30 -0
  121. lightrag/api/webui/assets/quadrantDiagram-AYHSOK5B-DURAK8QM.js +7 -0
  122. lightrag/api/webui/assets/requirementDiagram-UZGBJVZJ-RZlInJog.js +64 -0
  123. lightrag/api/webui/assets/sankeyDiagram-TZEHDZUN-CNaxQjSF.js +10 -0
  124. lightrag/api/webui/assets/sequenceDiagram-WL72ISMW-CaFAQyUz.js +145 -0
  125. lightrag/api/webui/assets/stateDiagram-FKZM4ZOC-B4FRWTvg.js +1 -0
  126. lightrag/api/webui/assets/stateDiagram-v2-4FDKWEC3-C_f0XKLw.js +1 -0
  127. lightrag/api/webui/assets/timeline-definition-IT6M3QCI-CJZgOy-y.js +61 -0
  128. lightrag/api/webui/assets/treemap-GDKQZRPO-CsQaPTHq.js +160 -0
  129. lightrag/api/webui/assets/xychartDiagram-PRI3JC2R-CfA_lR1M.js +7 -0
  130. lightrag/api/webui/index.html +17 -0
  131. lightrag/api/webui/logo.png +0 -0
  132. lightrag/api/webui/meshrag-favicon.png +0 -0
  133. lightrag/base.py +920 -0
  134. lightrag/constants.py +113 -0
  135. lightrag/evaluation/__init__.py +25 -0
  136. lightrag/evaluation/eval_rag_quality.py +1016 -0
  137. lightrag/exceptions.py +155 -0
  138. lightrag/kg/__init__.py +140 -0
  139. lightrag/kg/deprecated/chroma_impl.py +343 -0
  140. lightrag/kg/faiss_impl.py +583 -0
  141. lightrag/kg/json_doc_status_impl.py +426 -0
  142. lightrag/kg/json_kv_impl.py +302 -0
  143. lightrag/kg/memgraph_impl.py +1146 -0
  144. lightrag/kg/milvus_impl.py +1934 -0
  145. lightrag/kg/mongo_impl.py +2519 -0
  146. lightrag/kg/nano_vector_db_impl.py +428 -0
  147. lightrag/kg/neo4j_impl.py +1898 -0
  148. lightrag/kg/networkx_impl.py +570 -0
  149. lightrag/kg/postgres_impl.py +6166 -0
  150. lightrag/kg/qdrant_impl.py +1049 -0
  151. lightrag/kg/redis_impl.py +1165 -0
  152. lightrag/kg/shared_storage.py +1721 -0
  153. lightrag/lightrag.py +4603 -0
  154. lightrag/llm/__init__.py +0 -0
  155. lightrag/llm/anthropic.py +335 -0
  156. lightrag/llm/azure_openai.py +22 -0
  157. lightrag/llm/bedrock.py +485 -0
  158. lightrag/llm/binding_options.py +745 -0
  159. lightrag/llm/deprecated/siliconcloud.py +69 -0
  160. lightrag/llm/gemini.py +610 -0
  161. lightrag/llm/hf.py +177 -0
  162. lightrag/llm/jina.py +157 -0
  163. lightrag/llm/llama_index_impl.py +208 -0
  164. lightrag/llm/lmdeploy.py +154 -0
  165. lightrag/llm/lollms.py +177 -0
  166. lightrag/llm/nvidia_openai.py +68 -0
  167. lightrag/llm/ollama.py +243 -0
  168. lightrag/llm/openai.py +1096 -0
  169. lightrag/llm/zhipu.py +219 -0
  170. lightrag/namespace.py +28 -0
  171. lightrag/operate.py +5226 -0
  172. lightrag/prompt.py +605 -0
  173. lightrag/rerank.py +587 -0
  174. lightrag/tools/__init__.py +0 -0
  175. lightrag/tools/check_initialization.py +179 -0
  176. lightrag/tools/clean_llm_query_cache.py +1144 -0
  177. lightrag/tools/download_cache.py +200 -0
  178. lightrag/tools/lightrag_visualizer/__init__.py +0 -0
  179. lightrag/tools/lightrag_visualizer/graph_visualizer.py +1221 -0
  180. lightrag/tools/migrate_llm_cache.py +1472 -0
  181. lightrag/tools/prepare_qdrant_legacy_data.py +720 -0
  182. lightrag/types.py +29 -0
  183. lightrag/utils.py +3460 -0
  184. lightrag/utils_graph.py +1760 -0
  185. lightrag_webui/node_modules/flatted/python/flatted.py +149 -0
  186. lightrag_webui/node_modules/katex/src/fonts/generate_fonts.py +58 -0
  187. lightrag_webui/node_modules/katex/src/metrics/extract_tfms.py +114 -0
  188. lightrag_webui/node_modules/katex/src/metrics/extract_ttfs.py +122 -0
  189. lightrag_webui/node_modules/katex/src/metrics/format_json.py +28 -0
  190. lightrag_webui/node_modules/katex/src/metrics/parse_tfm.py +211 -0
  191. lightrag_webui/node_modules/micromark-extension-math/node_modules/katex/src/fonts/generate_fonts.py +58 -0
  192. lightrag_webui/node_modules/micromark-extension-math/node_modules/katex/src/metrics/extract_tfms.py +114 -0
  193. lightrag_webui/node_modules/micromark-extension-math/node_modules/katex/src/metrics/extract_ttfs.py +122 -0
  194. lightrag_webui/node_modules/micromark-extension-math/node_modules/katex/src/metrics/format_json.py +28 -0
  195. lightrag_webui/node_modules/micromark-extension-math/node_modules/katex/src/metrics/parse_tfm.py +211 -0
  196. lightrag_webui/node_modules/rehype-katex/node_modules/katex/src/fonts/generate_fonts.py +58 -0
  197. lightrag_webui/node_modules/rehype-katex/node_modules/katex/src/metrics/extract_tfms.py +114 -0
  198. lightrag_webui/node_modules/rehype-katex/node_modules/katex/src/metrics/extract_ttfs.py +122 -0
  199. lightrag_webui/node_modules/rehype-katex/node_modules/katex/src/metrics/format_json.py +28 -0
  200. lightrag_webui/node_modules/rehype-katex/node_modules/katex/src/metrics/parse_tfm.py +211 -0
  201. meshrag-1.0.0.dist-info/METADATA +385 -0
  202. meshrag-1.0.0.dist-info/RECORD +207 -0
  203. meshrag-1.0.0.dist-info/WHEEL +5 -0
  204. meshrag-1.0.0.dist-info/entry_points.txt +5 -0
  205. meshrag-1.0.0.dist-info/licenses/LICENSE +21 -0
  206. meshrag-1.0.0.dist-info/licenses/NOTICE +12 -0
  207. meshrag-1.0.0.dist-info/top_level.txt +2 -0
lightrag/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ from .lightrag import LightRAG as LightRAG, QueryParam as QueryParam
2
+
3
+ # MeshRAG's own version. The upstream lineage (forked from HKUDS/LightRAG
4
+ # v1.4.11) is recorded in CHANGELOG.md and the README files.
5
+ __version__ = "v1.0.0"
6
+ __author__ = "Zirui Guo"
7
+ __url__ = "https://github.com/tuxin-labs/meshrag"
@@ -0,0 +1 @@
1
+ __api_version__ = "0274"
lightrag/api/auth.py ADDED
@@ -0,0 +1,109 @@
1
+ from datetime import datetime, timedelta
2
+
3
+ import jwt
4
+ from dotenv import load_dotenv
5
+ from fastapi import HTTPException, status
6
+ from pydantic import BaseModel
7
+
8
+ from .config import global_args
9
+
10
+ # use the .env that is inside the current folder
11
+ # allows to use different .env file for each lightrag instance
12
+ # the OS environment variables take precedence over the .env file
13
+ load_dotenv(dotenv_path=".env", override=False)
14
+
15
+
16
+ class TokenPayload(BaseModel):
17
+ sub: str # Username
18
+ exp: datetime # Expiration time
19
+ role: str = "user" # User role, default is regular user
20
+ metadata: dict = {} # Additional metadata
21
+
22
+
23
+ class AuthHandler:
24
+ def __init__(self):
25
+ self.secret = global_args.token_secret
26
+ self.algorithm = global_args.jwt_algorithm
27
+ self.expire_hours = global_args.token_expire_hours
28
+ self.guest_expire_hours = global_args.guest_token_expire_hours
29
+ self.accounts = {}
30
+ auth_accounts = global_args.auth_accounts
31
+ if auth_accounts:
32
+ for account in auth_accounts.split(","):
33
+ username, password = account.split(":", 1)
34
+ self.accounts[username] = password
35
+
36
+ def create_token(
37
+ self,
38
+ username: str,
39
+ role: str = "user",
40
+ custom_expire_hours: int = None,
41
+ metadata: dict = None,
42
+ ) -> str:
43
+ """
44
+ Create JWT token
45
+
46
+ Args:
47
+ username: Username
48
+ role: User role, default is "user", guest is "guest"
49
+ custom_expire_hours: Custom expiration time (hours), if None use default value
50
+ metadata: Additional metadata
51
+
52
+ Returns:
53
+ str: Encoded JWT token
54
+ """
55
+ # Choose default expiration time based on role
56
+ if custom_expire_hours is None:
57
+ if role == "guest":
58
+ expire_hours = self.guest_expire_hours
59
+ else:
60
+ expire_hours = self.expire_hours
61
+ else:
62
+ expire_hours = custom_expire_hours
63
+
64
+ expire = datetime.utcnow() + timedelta(hours=expire_hours)
65
+
66
+ # Create payload
67
+ payload = TokenPayload(
68
+ sub=username, exp=expire, role=role, metadata=metadata or {}
69
+ )
70
+
71
+ return jwt.encode(payload.dict(), self.secret, algorithm=self.algorithm)
72
+
73
+ def validate_token(self, token: str) -> dict:
74
+ """
75
+ Validate JWT token
76
+
77
+ Args:
78
+ token: JWT token
79
+
80
+ Returns:
81
+ dict: Dictionary containing user information
82
+
83
+ Raises:
84
+ HTTPException: If token is invalid or expired
85
+ """
86
+ try:
87
+ payload = jwt.decode(token, self.secret, algorithms=[self.algorithm])
88
+ expire_timestamp = payload["exp"]
89
+ expire_time = datetime.utcfromtimestamp(expire_timestamp)
90
+
91
+ if datetime.utcnow() > expire_time:
92
+ raise HTTPException(
93
+ status_code=status.HTTP_401_UNAUTHORIZED, detail="Token expired"
94
+ )
95
+
96
+ # Return complete payload instead of just username
97
+ return {
98
+ "username": payload["sub"],
99
+ "role": payload.get("role", "user"),
100
+ "metadata": payload.get("metadata", {}),
101
+ "exp": expire_time,
102
+ }
103
+ except jwt.PyJWTError:
104
+ raise HTTPException(
105
+ status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token"
106
+ )
107
+
108
+
109
+ auth_handler = AuthHandler()