graphrag_sdk 0.2.2__tar.gz → 0.3.1__tar.gz

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 (50) hide show
  1. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/PKG-INFO +21 -19
  2. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/README.md +10 -14
  3. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/fixtures/prompts.py +2 -1
  4. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/models/azure_openai.py +32 -0
  5. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/models/gemini.py +23 -0
  6. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/models/ollama.py +32 -0
  7. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/models/openai.py +32 -0
  8. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/orchestrator.py +5 -5
  9. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/steps/graph_query_step.py +3 -10
  10. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/pyproject.toml +13 -5
  11. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/LICENSE +0 -0
  12. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/__init__.py +0 -0
  13. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/agents/__init__.py +0 -0
  14. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/agents/agent.py +0 -0
  15. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/agents/kg_agent.py +0 -0
  16. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/attribute.py +0 -0
  17. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/chat_session.py +0 -0
  18. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/document.py +0 -0
  19. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/document_loaders/__init__.py +0 -0
  20. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/document_loaders/csv.py +0 -0
  21. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/document_loaders/html.py +0 -0
  22. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/document_loaders/jsonl.py +0 -0
  23. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/document_loaders/pdf.py +0 -0
  24. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/document_loaders/text.py +0 -0
  25. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/document_loaders/url.py +0 -0
  26. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/entity.py +0 -0
  27. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/fixtures/regex.py +0 -0
  28. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/helpers.py +0 -0
  29. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/kg.py +0 -0
  30. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/model_config.py +0 -0
  31. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/models/__init__.py +0 -0
  32. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/models/model.py +0 -0
  33. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/ontology.py +0 -0
  34. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/__init__.py +0 -0
  35. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/execution_plan.py +0 -0
  36. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/orchestrator_decision.py +0 -0
  37. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/orchestrator_runner.py +0 -0
  38. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/step.py +0 -0
  39. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/step_result.py +0 -0
  40. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/steps/__init__.py +0 -0
  41. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/steps/agent.py +0 -0
  42. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/steps/parallel.py +0 -0
  43. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/steps/summary.py +0 -0
  44. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/orchestrator/steps/user_input.py +0 -0
  45. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/relation.py +0 -0
  46. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/source.py +0 -0
  47. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/steps/Step.py +0 -0
  48. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/steps/create_ontology_step.py +0 -0
  49. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/steps/extract_data_step.py +0 -0
  50. {graphrag_sdk-0.2.2 → graphrag_sdk-0.3.1}/graphrag_sdk/steps/qa_step.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: graphrag_sdk
3
- Version: 0.2.2
3
+ Version: 0.3.1
4
4
  Summary:
5
5
  Home-page: http://RAG-SDK.readthedocs.io
6
6
  License: MIT
@@ -15,20 +15,26 @@ Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
17
  Classifier: Programming Language :: Python :: 3.13
18
+ Provides-Extra: all
19
+ Provides-Extra: google-generativeai
20
+ Provides-Extra: ollama
21
+ Provides-Extra: openai
22
+ Provides-Extra: vertexai
18
23
  Requires-Dist: backoff (>=2.2.1,<3.0.0)
19
24
  Requires-Dist: bs4 (>=0.0.2,<0.0.3)
20
25
  Requires-Dist: falkordb (>=1.0.9,<2.0.0)
21
26
  Requires-Dist: fix-busted-json (>=0.0.18,<0.0.19)
22
- Requires-Dist: google-generativeai (>=0.8.1,<0.9.0)
27
+ Requires-Dist: google-generativeai (>=0.8.1,<0.9.0) ; extra == "all" or extra == "google-generativeai"
23
28
  Requires-Dist: ipykernel (>=6.29.5,<7.0.0)
24
- Requires-Dist: ollama (>=0.2.1,<0.3.0)
25
- Requires-Dist: openai (>=1.35.9,<2.0.0)
29
+ Requires-Dist: ollama (>=0.2.1,<0.3.0) ; extra == "all" or extra == "ollama"
30
+ Requires-Dist: openai (>=1.35.9,<2.0.0) ; extra == "all" or extra == "openai"
26
31
  Requires-Dist: pypdf (>=4.2.0,<5.0.0)
27
32
  Requires-Dist: python-abc (>=0.2.0,<0.3.0)
28
33
  Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
29
34
  Requires-Dist: ratelimit (>=2.2.1,<3.0.0)
35
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
30
36
  Requires-Dist: typing-extensions (>=4.12.1,<5.0.0)
31
- Requires-Dist: vertexai (>=1.49.0,<2.0.0)
37
+ Requires-Dist: vertexai (>=1.49.0,<2.0.0) ; extra == "all" or extra == "vertexai"
32
38
  Project-URL: Repository, https://github.com/FalkorDB/GraphRAG-SDK
33
39
  Description-Content-Type: text/markdown
34
40
 
@@ -55,7 +61,13 @@ GraphRAG-SDK is a comprehensive solution for building Graph Retrieval-Augmented
55
61
  ### Install
56
62
 
57
63
  ```sh
58
- pip install graphrag_sdk
64
+ pip install graphrag_sdk[all]
65
+ ```
66
+
67
+ or (if only OpenAI is required)
68
+
69
+ ```sh
70
+ pip install graphrag_sdk[openai]
59
71
  ```
60
72
 
61
73
  ### Prerequisites
@@ -75,19 +87,9 @@ docker run -p 6379:6379 -p 3000:3000 -it --rm -v ./data:/data falkordb/falkordb
75
87
  Currently, this SDK supports the following LLMs API:
76
88
 
77
89
  * [OpenAI](https://openai.com/index/openai-api) Recommended model:`gpt-4o`
78
- * [google](https://makersuite.google.com/app/apikey) Recommended model:`gemini-1.5-flash-001`
79
-
80
- Make sure that a `.env` file is present with all required credentials.
81
-
82
- <details>
83
- <summary>.env</summary>
84
-
85
- ```
86
- OPENAI_API_KEY="OPENAI_API_KEY"
87
- GOOGLE_API_KEY="GOOGLE_API_KEY"
88
- ```
89
-
90
- </details>
90
+ * [Google](https://makersuite.google.com/app/apikey) Recommended model:`gemini-1.5-flash-001`
91
+ * [Azure-OpenAI](https://ai.azure.com) Recommended model:`gpt-4o`
92
+ * [Ollama](https://ollama.com/) Available only to the Q&A step. Recommended models: `llama3`. Ollama models are suitable for the Q&A step only (after the knowledge graph (KG) created).
91
93
 
92
94
  ## Basic Usage
93
95
 
@@ -21,7 +21,13 @@ GraphRAG-SDK is a comprehensive solution for building Graph Retrieval-Augmented
21
21
  ### Install
22
22
 
23
23
  ```sh
24
- pip install graphrag_sdk
24
+ pip install graphrag_sdk[all]
25
+ ```
26
+
27
+ or (if only OpenAI is required)
28
+
29
+ ```sh
30
+ pip install graphrag_sdk[openai]
25
31
  ```
26
32
 
27
33
  ### Prerequisites
@@ -41,19 +47,9 @@ docker run -p 6379:6379 -p 3000:3000 -it --rm -v ./data:/data falkordb/falkordb
41
47
  Currently, this SDK supports the following LLMs API:
42
48
 
43
49
  * [OpenAI](https://openai.com/index/openai-api) Recommended model:`gpt-4o`
44
- * [google](https://makersuite.google.com/app/apikey) Recommended model:`gemini-1.5-flash-001`
45
-
46
- Make sure that a `.env` file is present with all required credentials.
47
-
48
- <details>
49
- <summary>.env</summary>
50
-
51
- ```
52
- OPENAI_API_KEY="OPENAI_API_KEY"
53
- GOOGLE_API_KEY="GOOGLE_API_KEY"
54
- ```
55
-
56
- </details>
50
+ * [Google](https://makersuite.google.com/app/apikey) Recommended model:`gemini-1.5-flash-001`
51
+ * [Azure-OpenAI](https://ai.azure.com) Recommended model:`gpt-4o`
52
+ * [Ollama](https://ollama.com/) Available only to the Q&A step. Recommended models: `llama3`. Ollama models are suitable for the Q&A step only (after the knowledge graph (KG) created).
57
53
 
58
54
  ## Basic Usage
59
55
 
@@ -441,9 +441,10 @@ RETURN m, s
441
441
  """
442
442
 
443
443
  CYPHER_GEN_PROMPT = """
444
- Using the ontology provided, generate an OpenCypher statement to query the graph database returning all relevant entities, relationships, and attributes to answer the question below:
444
+ Using the ontology provided, generate an OpenCypher statement to query the graph database returning all relevant entities, relationships, and attributes to answer the question below.
445
445
  If you cannot generate a OpenCypher statement for any reason, return an empty string.
446
446
  Respect the order of the relationships, the arrows should always point from the "source" to the "target".
447
+ Please think if your answer is a valid Cypher query, and correct it if it is not.
447
448
 
448
449
  Question: {question}
449
450
  """
@@ -227,3 +227,35 @@ class AzureOpenAiChatSession(GenerativeModelChatSession):
227
227
  config['response_format'] = { "type": "json_object" }
228
228
 
229
229
  return config
230
+
231
+ def delete_last_message(self):
232
+ """
233
+ Deletes the last message exchange (user message and assistant response) from the chat history.
234
+ Preserves the system message if present.
235
+
236
+ Example:
237
+ Before:
238
+ [
239
+ {"role": "system", "content": "System message"},
240
+ {"role": "user", "content": "User message"},
241
+ {"role": "assistant", "content": "Assistant response"},
242
+ ]
243
+ After:
244
+ [
245
+ {"role": "system", "content": "System message"},
246
+ ]
247
+
248
+ Note: Does nothing if the chat history is empty or contains only a system message.
249
+ """
250
+ # Keep at least the system message if present
251
+ min_length = 1 if self._model.system_instruction else 0
252
+ if len(self._history) - 2 >= min_length:
253
+ self._history.pop()
254
+ self._history.pop()
255
+ else:
256
+ # Reset to initial state with just system message if present
257
+ self._history = (
258
+ [{"role": "system", "content": self._model.system_instruction}]
259
+ if self._model.system_instruction is not None
260
+ else []
261
+ )
@@ -117,3 +117,26 @@ class GeminiChatSession(GenerativeModelChatSession):
117
117
  "temperature": 0
118
118
  }
119
119
  return self._model._generation_config
120
+
121
+ def delete_last_message(self):
122
+ """
123
+ Deletes the last message exchange (user message and assistant response) from the chat history.
124
+ Preserves the system message if present.
125
+
126
+ Example:
127
+ Before:
128
+ [
129
+ {"role": "user", "content": "User message"},
130
+ {"role": "assistant", "content": "Assistant response"},
131
+ ]
132
+ After:
133
+ []
134
+
135
+ Note: Does nothing if the chat history is empty or contains only a system message.
136
+ """
137
+ if len(self._chat_session.history) >= 2:
138
+ self._chat_session.history.pop()
139
+ self._chat_session.history.pop()
140
+ else:
141
+ self._chat_session.history = []
142
+
@@ -216,3 +216,35 @@ class OllamaChatSession(GenerativeModelChatSession):
216
216
  config['format'] = 'json'
217
217
 
218
218
  return config
219
+
220
+ def delete_last_message(self):
221
+ """
222
+ Deletes the last message exchange (user message and assistant response) from the chat history.
223
+ Preserves the system message if present.
224
+
225
+ Example:
226
+ Before:
227
+ [
228
+ {"role": "system", "content": "System message"},
229
+ {"role": "user", "content": "User message"},
230
+ {"role": "assistant", "content": "Assistant response"},
231
+ ]
232
+ After:
233
+ [
234
+ {"role": "system", "content": "System message"},
235
+ ]
236
+
237
+ Note: Does nothing if the chat history is empty or contains only a system message.
238
+ """
239
+ # Keep at least the system message if present
240
+ min_length = 1 if self._model.system_instruction else 0
241
+ if len(self._chat_history) - 2 >= min_length:
242
+ self._chat_history.pop()
243
+ self._chat_history.pop()
244
+ else:
245
+ # Reset to initial state with just system message if present
246
+ self._chat_history = (
247
+ [{"role": "system", "content": self._model.system_instruction}]
248
+ if self._model.system_instruction is not None
249
+ else []
250
+ )
@@ -106,3 +106,35 @@ class OpenAiChatSession(GenerativeModelChatSession):
106
106
  config['response_format'] = { "type": "json_object" }
107
107
 
108
108
  return config
109
+
110
+ def delete_last_message(self):
111
+ """
112
+ Deletes the last message exchange (user message and assistant response) from the chat history.
113
+ Preserves the system message if present.
114
+
115
+ Example:
116
+ Before:
117
+ [
118
+ {"role": "system", "content": "System message"},
119
+ {"role": "user", "content": "User message"},
120
+ {"role": "assistant", "content": "Assistant response"},
121
+ ]
122
+ After:
123
+ [
124
+ {"role": "system", "content": "System message"},
125
+ ]
126
+
127
+ Note: Does nothing if the chat history is empty or contains only a system message.
128
+ """
129
+ # Keep at least the system message if present
130
+ min_length = 1 if self._model.system_instruction else 0
131
+ if len(self._history) - 2 >= min_length:
132
+ self._history.pop()
133
+ self._history.pop()
134
+ else:
135
+ # Reset to initial state with just system message if present
136
+ self._history = (
137
+ [{"role": "system", "content": self._model.system_instruction}]
138
+ if self._model.system_instruction is not None
139
+ else []
140
+ )
@@ -1,5 +1,6 @@
1
- from graphrag_sdk.models import GenerativeModel
2
1
  from graphrag_sdk.agents import Agent
2
+ from graphrag_sdk.models import GenerativeModel
3
+ from graphrag_sdk.models.model import OutputMethod
3
4
  from .orchestrator_runner import OrchestratorRunner
4
5
  from graphrag_sdk.fixtures.prompts import (
5
6
  ORCHESTRATOR_SYSTEM,
@@ -16,13 +17,12 @@ logger = logging.getLogger(__name__)
16
17
 
17
18
  class Orchestrator:
18
19
 
19
- _agents = []
20
- _chat = None
21
-
22
20
  def __init__(self, model: GenerativeModel, backstory: str = ""):
23
21
  self._model = model
24
22
  self._backstory = backstory
25
-
23
+ self._agents = []
24
+ self._chat = None
25
+
26
26
  def _get_chat(self):
27
27
  if self._chat is None:
28
28
  self._chat = self._model.with_system_instruction(
@@ -40,20 +40,14 @@ class GraphQueryGenerationStep(Step):
40
40
  self.chat_session = chat_session
41
41
  self.last_answer = last_answer
42
42
 
43
- def run(self, question: str, retries: int = 5):
44
- error = False
45
-
43
+ def run(self, question: str, retries: int = 10):
46
44
  cypher = ""
47
- while error is not None and retries > 0:
45
+ for i in range(retries):
48
46
  try:
49
47
  cypher_prompt = (
50
48
  (CYPHER_GEN_PROMPT.format(question=question)
51
49
  if self.last_answer is None
52
50
  else CYPHER_GEN_PROMPT_WITH_HISTORY.format(question=question, last_answer=self.last_answer))
53
- if error is False
54
- else CYPHER_GEN_PROMPT_WITH_ERROR.format(
55
- question=question, error=error
56
- )
57
51
  )
58
52
  logger.debug(f"Cypher Prompt: {cypher_prompt}")
59
53
  cypher_statement_response = self.chat_session.send_message(
@@ -67,7 +61,6 @@ class GraphQueryGenerationStep(Step):
67
61
  return (None, None)
68
62
 
69
63
  validation_errors = validate_cypher(cypher, self.ontology)
70
- # print(f"Is valid: {is_valid}")
71
64
  if validation_errors is not None:
72
65
  raise Exception("\n".join(validation_errors))
73
66
 
@@ -82,6 +75,6 @@ class GraphQueryGenerationStep(Step):
82
75
  except Exception as e:
83
76
  logger.debug(f"Error: {e}")
84
77
  error = e
85
- retries -= 1
78
+ self.chat_session.delete_last_message()
86
79
 
87
80
  raise Exception("Failed to generate Cypher query: " + str(error))
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "graphrag_sdk"
3
- version = "0.2.2"
3
+ version = "0.3.1"
4
4
  license = "MIT"
5
5
  description = ""
6
6
  authors = ["FalkorDB <info@falkordb.com>"]
@@ -15,16 +15,24 @@ falkordb = "^1.0.9"
15
15
  typing-extensions = "^4.12.1"
16
16
  bs4 = "^0.0.2"
17
17
  pypdf = "^4.2.0"
18
- vertexai = "^1.49.0"
19
18
  backoff = "^2.2.1"
19
+ requests = "^2.32.3"
20
20
  python-abc = "^0.2.0"
21
21
  ratelimit = "^2.2.1"
22
22
  python-dotenv = "^1.0.1"
23
- openai = "^1.35.9"
24
23
  fix-busted-json = "^0.0.18"
25
- ollama = "^0.2.1"
26
24
  ipykernel = "^6.29.5"
27
- google-generativeai = "^0.8.1"
25
+ vertexai = { version = "^1.49.0", optional = true }
26
+ ollama = { version = "^0.2.1", optional = true }
27
+ openai = { version = "^1.35.9", optional = true }
28
+ google-generativeai = { version = "^0.8.1", optional = true }
29
+
30
+ [tool.poetry.extras]
31
+ all = ["vertexai", "ollama", "openai", "google-generativeai"]
32
+ ollama = ["ollama"]
33
+ openai = ["openai"]
34
+ vertexai = ["vertexai"]
35
+ google-generativeai = ["google-generativeai"]
28
36
 
29
37
  [tool.poetry.group.test.dependencies]
30
38
  pytest = "^8.2.1"
File without changes