Skip to content

Commit e3fb1fb

Browse files
authored
Merge branch 'FalkorDB:main' into main
2 parents 9fd5354 + 3e38744 commit e3fb1fb

File tree

8 files changed

+204
-149
lines changed

8 files changed

+204
-149
lines changed

.wordlist.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ scalable
3737
APIs
3838
Embeddings
3939
NLP
40-
graphrag
40+
graphrag
41+
gemini

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Dockerhub](https://img.shields.io/docker/pulls/falkordb/falkordb?label=Docker)](https://hub.docker.com/r/falkordb/falkordb/)
33
[![pypi](https://badge.fury.io/py/graphrag_sdk.svg)](https://pypi.org/project/graphrag_sdk/)
44
[![Discord](https://img.shields.io/discord/1146782921294884966?style=flat-square)](https://discord.gg/6M4QwDXn2w)
5-
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
5+
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
66

77
<p align="center">
88
<img alt="FalkorDB GraphRAG-SDK README Banner" src="images/FalkorDB GraphRAG-SDK README Banner.png" width="1500">
@@ -34,14 +34,17 @@ pip install graphrag_sdk[litellm]
3434

3535
### Configure Credentials. See [.env](.env.template) for examples.
3636

37-
* [LiteLLM](https://docs.litellm.ai): A framework supporting inference of large language models, allowing flexibility in deployment and use cases.
37+
* [LiteLLM](https://docs.litellm.ai): A framework supporting inference of large language models, allowing flexibility in deployment and use cases.
38+
To choose vendor use the prefix "specific_vendor/your_model", for example "gemini/gemini-2.0-flash-exp".
3839
* [OpenAI](https://openai.com/index/openai-api) Recommended model:`gpt-4o`
3940
* [Google](https://makersuite.google.com/app/apikey) Recommended model:`gemini-2.0-flash-exp`
4041
* [Azure-OpenAI](https://ai.azure.com) Recommended model:`gpt-4o`
4142
* [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).
4243

4344

4445
# How to use
46+
[![Get started](https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/get-started-badge.svg)](https://lightning.ai/muhammadqadora/studios/build-fast-accurate-genai-apps-advanced-rag-with-falkordb)
47+
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/FalkorDB/GraphRAG-SDK/blob/main/examples/movies/demo-movies.ipynb)
4548

4649
### Step 1: Creating Ontologies
4750
Automate ontology creation from unstructured data or define it manually - See [example](https://github.com/liorkesos/GraphRAG-SDK/blob/main/examples/trip/demo_orchestrator_trip.ipynb)
@@ -65,7 +68,7 @@ urls = ["https://www.rottentomatoes.com/m/side_by_side_2012",
6568

6669
sources = [URL(url) for url in urls]
6770

68-
# Model
71+
# Model - vendor: gemini, model: gemini-2.0-flash-exp -> gemini/gemini-2.0-flash-exp
6972
model = LiteModel(model_name="gemini/gemini-2.0-flash-exp")
7073

7174
# Ontology Auto-Detection

examples/movies/demo-movies.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"metadata": {},
5151
"outputs": [],
5252
"source": [
53+
"# Get your Credentails from google website, see https://aistudio.google.com/\n",
5354
"os.environ[\"GEMINI_API_KEY\"] = \"\"\n",
5455
"\n",
5556
"# Get your Credentails from Falkor website, see https://app.falkordb.cloud\n",

graphrag_sdk/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
2-
import graphrag_sdk
32
import logging
3+
import graphrag_sdk
44
from fix_busted_json import repair_json
55

66
logger = logging.getLogger(__name__)
@@ -215,4 +215,4 @@ def validate_cypher_relation_directions(
215215
except Exception:
216216
continue
217217

218-
return errors
218+
return errors

graphrag_sdk/kg.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def __init__(
7878
self._name = name
7979
self._model_config = model_config
8080
self.sources = set([])
81+
self.failed_sources = set([])
8182

8283
if cypher_system_instruction is None:
8384
cypher_system_instruction = CYPHER_GEN_SYSTEM
@@ -146,38 +147,47 @@ def list_sources(self) -> list[AbstractSource]:
146147
return [s.source for s in self.sources]
147148

148149
def process_sources(
149-
self, sources: list[AbstractSource], instructions: str = None
150+
self, sources: list[AbstractSource], instructions: str = None, hide_progress: bool = False
150151
) -> None:
151152
"""
152153
Add entities and relations found in sources into the knowledge-graph
153154
154155
Parameters:
155156
sources (list[AbstractSource]): list of sources to extract knowledge from
157+
instructions (str): instructions to use for extraction
158+
hide_progress (bool): hide progress bar
156159
"""
157160

158161
if self.ontology is None:
159162
raise Exception("Ontology is not defined")
160163

161164
# Create graph with sources
162-
self._create_graph_with_sources(sources, instructions)
165+
failed_sources = self._create_graph_with_sources(sources, instructions, hide_progress)
163166

164167
# Add processed sources
165168
for src in sources:
166-
self.sources.add(src)
169+
if src not in failed_sources:
170+
self.sources.add(src)
171+
self.failed_sources.discard(src)
172+
else:
173+
self.failed_sources.add(src)
167174

168175
def _create_graph_with_sources(
169-
self, sources: list[AbstractSource] | None = None, instructions: str = None
170-
):
176+
self, sources: list[AbstractSource] | None = None, instructions: str = None, hide_progress: bool = False
177+
) -> list[AbstractSource]:
171178

172179
step = ExtractDataStep(
173180
sources=list(sources),
174181
ontology=self.ontology,
175182
model=self._model_config.extract_data,
176183
graph=self.graph,
184+
hide_progress=hide_progress,
177185
)
178186

179-
step.run(instructions)
180-
187+
failed_sources = step.run(instructions)
188+
189+
return failed_sources
190+
181191
def delete(self) -> None:
182192
"""
183193
Deletes the knowledge graph and any other related resource

graphrag_sdk/ontology.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, entities: list[Entity] = None, relations: list[Relation] = No
2525
"""
2626
Initialize the Ontology class.
2727
28-
Args:
28+
Parameters:
2929
entities (list[Entity], optional): List of Entity objects. Defaults to None.
3030
relations (list[Relation], optional): List of Relation objects. Defaults to None.
3131
"""
@@ -37,14 +37,16 @@ def from_sources(
3737
sources: list[AbstractSource],
3838
model: GenerativeModel,
3939
boundaries: Optional[str] = None,
40+
hide_progress: bool = False,
4041
) -> "Ontology":
4142
"""
4243
Create an Ontology object from a list of sources.
4344
44-
Args:
45+
Parameters:
4546
sources (list[AbstractSource]): A list of AbstractSource objects representing the sources.
4647
boundaries (Optinal[str]): The boundaries for the ontology.
4748
model (GenerativeModel): The generative model to use.
49+
hide_progress (bool): Whether to hide the progress bar.
4850
4951
Returns:
5052
The created Ontology object.
@@ -53,6 +55,7 @@ def from_sources(
5355
sources=sources,
5456
ontology=Ontology(),
5557
model=model,
58+
hide_progress=hide_progress,
5659
)
5760

5861
return step.run(boundaries=boundaries)
@@ -62,7 +65,7 @@ def from_json(txt: dict | str):
6265
"""
6366
Creates an Ontology object from a JSON representation.
6467
65-
Args:
68+
Parameters:
6669
txt (dict | str): The JSON representation of the ontology. It can be either a dictionary or a string.
6770
6871
Returns:
@@ -82,7 +85,7 @@ def from_graph(graph: Graph):
8285
"""
8386
Creates an Ontology object from a given graph.
8487
85-
Args:
88+
Parameters:
8689
graph (Graph): The graph object representing the ontology.
8790
8891
Returns:
@@ -114,7 +117,7 @@ def add_relation(self, relation: Relation):
114117
"""
115118
Adds a relation to the ontology.
116119
117-
Args:
120+
Parameters:
118121
relation (Relation): The relation to be added.
119122
"""
120123
self.relations.append(relation)
@@ -135,7 +138,7 @@ def merge_with(self, o: "Ontology"):
135138
"""
136139
Merges the given ontology `o` with the current ontology.
137140
138-
Args:
141+
Parameters:
139142
o (Ontology): The ontology to merge with.
140143
141144
Returns:
@@ -256,7 +259,7 @@ def get_entity_with_label(self, label: str):
256259
"""
257260
Retrieves the entity with the specified label.
258261
259-
Args:
262+
Parameters:
260263
label (str): The label of the entity to retrieve.
261264
262265
Returns:
@@ -318,7 +321,7 @@ def save_to_graph(self, graph: Graph):
318321
"""
319322
Saves the entities and relations to the specified graph.
320323
321-
Args:
324+
Parameters:
322325
graph (Graph): The graph to save the entities and relations to.
323326
"""
324327
for entity in self.entities:

0 commit comments

Comments
 (0)