Skip to content

Commit 87dbb96

Browse files
committed
Updated component docs
1 parent b2f69c8 commit 87dbb96

File tree

9 files changed

+264
-20
lines changed

9 files changed

+264
-20
lines changed

docs/source/api.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,66 @@
33
API Documentation
44
#################
55

6+
.. _components-section:
7+
8+
**********
9+
Components
10+
**********
11+
12+
KGWriter
13+
========
14+
15+
.. autoclass:: neo4j_genai.components.kg_writer.KGWriter
16+
:members: run
17+
18+
Neo4jWriter
19+
===========
20+
21+
.. autoclass:: neo4j_genai.components.kg_writer.Neo4jWriter
22+
:members: run
23+
24+
TextSplitter
25+
============
26+
27+
.. autoclass:: neo4j_genai.components.text_splitters.base.TextSplitter
28+
:members: run
29+
30+
LangChainTextSplitterAdapter
31+
============================
32+
33+
.. autoclass:: neo4j_genai.components.text_splitters.langchain.LangChainTextSplitterAdapter
34+
:members: run
35+
36+
LlamaIndexTextSplitterAdapter
37+
=============================
38+
39+
.. autoclass:: neo4j_genai.components.text_splitters.llamaindex.LlamaIndexTextSplitterAdapter
40+
:members: run
41+
42+
TextChunkEmbedder
43+
=================
44+
45+
.. autoclass:: neo4j_genai.components.embedder.TextChunkEmbedder
46+
:members: run
47+
48+
SchemaBuilder
49+
=============
50+
51+
.. autoclass:: neo4j_genai.components.schema.SchemaBuilder
52+
:members: run
53+
54+
EntityRelationExtractor
55+
=======================
56+
57+
.. autoclass:: neo4j_genai.components.entity_relation_extractor.EntityRelationExtractor
58+
:members: run
59+
60+
LLMEntityRelationExtractor
61+
==========================
62+
63+
.. autoclass:: neo4j_genai.components.entity_relation_extractor.LLMEntityRelationExtractor
64+
:members: run
65+
666
.. _retrievers-section:
767

868
**********

docs/source/types.rst

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,80 @@ Types
55
*****
66

77
RawSearchResult
8-
==================
8+
===============
99

1010
.. autoclass:: neo4j_genai.types.RawSearchResult
1111

1212

1313
RetrieverResult
14-
==================
14+
===============
1515

1616
.. autoclass:: neo4j_genai.types.RetrieverResult
1717

1818

1919
RetrieverResultItem
20-
====================
20+
===================
2121

2222
.. autoclass:: neo4j_genai.types.RetrieverResultItem
2323

2424

2525
LLMResponse
26-
====================
26+
===========
2727

2828
.. autoclass:: neo4j_genai.llm.types.LLMResponse
2929

3030

3131
RagResultModel
32-
====================
32+
==============
3333

3434
.. autoclass:: neo4j_genai.generation.types.RagResultModel
35+
36+
TextChunk
37+
=========
38+
39+
.. autoclass:: neo4j_genai.components.types.TextChunk
40+
41+
TextChunks
42+
==========
43+
44+
.. autoclass:: neo4j_genai.components.types.TextChunks
45+
46+
Neo4jNode
47+
=========
48+
49+
.. autoclass:: neo4j_genai.components.types.Neo4jNode
50+
51+
Neo4jRelationship
52+
=================
53+
54+
.. autoclass:: neo4j_genai.components.types.Neo4jRelationship
55+
56+
Neo4jGraph
57+
==========
58+
59+
.. autoclass:: neo4j_genai.components.types.Neo4jGraph
60+
61+
KGWriterModel
62+
=============
63+
64+
.. autoclass:: neo4j_genai.components.kg_writer.KGWriterModel
65+
66+
SchemaProperty
67+
==============
68+
69+
.. autoclass:: neo4j_genai.components.schema.SchemaProperty
70+
71+
SchemaEntity
72+
============
73+
74+
.. autoclass:: neo4j_genai.components.schema.SchemaEntity
75+
76+
SchemaRelation
77+
==============
78+
79+
.. autoclass:: neo4j_genai.components.schema.SchemaEntity
80+
81+
SchemaConfig
82+
==============
83+
84+
.. autoclass:: neo4j_genai.components.schema.SchemaConfig

src/neo4j_genai/components/embedder.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ class TextChunkEmbedder(Component):
2222
2323
Args:
2424
embedder (Embedder): The embedder to use to create the embeddings.
25+
26+
Example:
27+
28+
.. code-block:: python
29+
30+
from neo4j_genai.components.embedder import TextChunkEmbedder
31+
from neo4j_genai.embeddings.openai import OpenAIEmbeddings
32+
from neo4j_genai.pipeline import Pipeline
33+
34+
embedder = OpenAIEmbeddings(model="text-embedding-3-large")
35+
chunk_embedder = TextChunkEmbedder(embedder)
36+
pipeline = Pipeline()
37+
pipeline.add_component("chunk_embedder", chunk_embedder)
38+
2539
"""
2640

2741
def __init__(self, embedder: Embedder):

src/neo4j_genai/components/entity_relation_extractor.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class OnError(enum.Enum):
5151

5252

5353
class EntityRelationExtractor(Component, abc.ABC):
54+
"""Abstract class for entity relation extraction components.
55+
56+
Args:
57+
on_error (OnError): What to do when an error occurs during extraction. Defaults to raising an error.
58+
create_lexical_graph (bool): Whether to include the text chunks in the graph in addition to the extracted entities and relations. Defaults to True.
59+
"""
60+
5461
def __init__(
5562
self,
5663
*args: Any,
@@ -137,6 +144,31 @@ def build_lexical_graph(
137144

138145

139146
class LLMEntityRelationExtractor(EntityRelationExtractor):
147+
"""
148+
Extracts a knowledge graph from a series of text chunks using a large language model.
149+
150+
Args:
151+
llm (LLMInterface): The language model to use for extraction.
152+
prompt_template (ERExtractionTemplate | str): A custom prompt template to use for extraction.
153+
create_lexical_graph (bool): Whether to include the text chunks in the graph in addition to the extracted entities and relations. Defaults to True.
154+
on_error (OnError): What to do when an error occurs during extraction. Defaults to raising an error.
155+
156+
Example:
157+
158+
.. code-block:: python
159+
160+
from neo4j_genai.components.entity_relation_extractor import LLMEntityRelationExtractor
161+
from neo4j_genai.llm import OpenAILLM
162+
from neo4j_genai.pipeline import Pipeline
163+
164+
llm = OpenAILLM(model_name="gpt-4o", model_params={"temperature": 0})
165+
166+
extractor = LLMEntityRelationExtractor(llm=llm)
167+
pipe = Pipeline()
168+
pipe.add_component("extractor", extractor)
169+
170+
"""
171+
140172
def __init__(
141173
self,
142174
llm: LLMInterface,

src/neo4j_genai/components/kg_writer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ class Neo4jWriter(KGWriter):
6060
Args:
6161
driver (neo4j.driver): The Neo4j driver to connect to the database.
6262
neo4j_database (Optional[str]): The name of the Neo4j database to write to. Defaults to 'neo4j' if not provided.
63+
64+
Example:
65+
66+
.. code-block:: python
67+
68+
from neo4j import GraphDatabase
69+
from neo4j_genai.components.kg_writer import Neo4jWriter
70+
from neo4j_genai.pipeline import Pipeline
71+
72+
URI = "neo4j://localhost:7687"
73+
AUTH = ("neo4j", "password")
74+
DATABASE = "neo4j"
75+
76+
driver = GraphDatabase.driver(URI, auth=AUTH, database=DATABASE)
77+
writer = Neo4jWriter(driver=driver, neo4j_database=DATABASE)
78+
79+
pipeline = Pipeline()
80+
pipeline.add_component("writer", writer)
81+
6382
"""
6483

6584
def __init__(

src/neo4j_genai/components/schema.py

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
# Copyright (c) "Neo4j"
16-
# Neo4j Sweden AB [https://neo4j.com]
17-
# #
18-
# Licensed under the Apache License, Version 2.0 (the "License");
19-
# you may not use this file except in compliance with the License.
20-
# You may obtain a copy of the License at
21-
# #
22-
# https://www.apache.org/licenses/LICENSE-2.0
23-
# #
24-
# Unless required by applicable law or agreed to in writing, software
25-
# distributed under the License is distributed on an "AS IS" BASIS,
26-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27-
# See the License for the specific language governing permissions and
28-
# limitations under the License.
2915
from __future__ import annotations
3016

3117
from typing import Any, Dict, List, Literal, Tuple
@@ -37,6 +23,10 @@
3723

3824

3925
class SchemaProperty(BaseModel):
26+
"""
27+
Represents a property on a node or relationship in the graph.
28+
"""
29+
4030
name: str
4131
# See https://neo4j.com/docs/cypher-manual/current/values-and-types/property-structural-constructed/#property-types
4232
type: Literal[
@@ -112,6 +102,59 @@ class SchemaBuilder(Component):
112102
"""
113103
A builder class for constructing SchemaConfig objects from given entities,
114104
relations, and their interrelationships defined in a potential schema.
105+
106+
Example:
107+
108+
.. code-block:: python
109+
110+
from neo4j_genai.components.schema import (
111+
SchemaBuilder,
112+
SchemaEntity,
113+
SchemaProperty,
114+
SchemaRelation,
115+
)
116+
from neo4j_genai.pipeline import Pipeline
117+
118+
entities = [
119+
SchemaEntity(
120+
label="PERSON",
121+
description="An individual human being.",
122+
properties=[
123+
SchemaProperty(
124+
name="name", type="STRING", description="The name of the person"
125+
)
126+
],
127+
),
128+
SchemaEntity(
129+
label="ORGANIZATION",
130+
description="A structured group of people with a common purpose.",
131+
properties=[
132+
SchemaProperty(
133+
name="name", type="STRING", description="The name of the organization"
134+
)
135+
],
136+
),
137+
]
138+
relations = [
139+
SchemaRelation(
140+
label="EMPLOYED_BY", description="Indicates employment relationship."
141+
),
142+
]
143+
potential_schema = [
144+
("PERSON", "EMPLOYED_BY", "ORGANIZATION"),
145+
]
146+
pipe = Pipeline()
147+
schema_builder = SchemaBuilder()
148+
pipe.add_component("schema_builder", schema_builder)
149+
pipe_inputs = {
150+
"schema": {
151+
"entities": entities,
152+
"relations": relations,
153+
"potential_schema": potential_schema,
154+
},
155+
...
156+
}
157+
pipe.run(pipe_inputs)
115158
"""
116159

117160
@staticmethod

src/neo4j_genai/components/text_splitters/langchain.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ class LangChainTextSplitterAdapter(TextSplitter):
2626
2727
Args:
2828
text_splitter (LangChainTextSplitter): An instance of LangChain's TextSplitter class.
29+
30+
Example:
31+
32+
.. code-block:: python
33+
34+
from langchain_text_splitters import RecursiveCharacterTextSplitter
35+
from neo4j_genai.components.text_splitters.langchain import LangChainTextSplitterAdapter
36+
from neo4j_genai.pipeline import Pipeline
37+
38+
pipeline = Pipeline()
39+
text_splitter = LangChainTextSplitterAdapter(RecursiveCharacterTextSplitter())
40+
pipeline.add_component("text_splitter", text_splitter)
41+
2942
"""
3043

3144
def __init__(self, text_splitter: LangChainTextSplitter) -> None:

src/neo4j_genai/components/text_splitters/llamaindex.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ class LlamaIndexTextSplitterAdapter(TextSplitter):
2626
2727
Args:
2828
text_splitter (LlamaIndexTextSplitter): An instance of LlamaIndex's TextSplitter class.
29+
30+
Example:
31+
32+
.. code-block:: python
33+
34+
from llama_index.core.node_parser.text.sentence import SentenceSplitter
35+
from neo4j_genai.components.text_splitters.langchain import LangChainTextSplitterAdapter
36+
from neo4j_genai.pipeline import Pipeline
37+
38+
pipeline = Pipeline()
39+
text_splitter = LlamaIndexTextSplitterAdapter(SentenceSplitter())
40+
pipeline.add_component("text_splitter", text_splitter)
41+
2942
"""
3043

3144
def __init__(self, text_splitter: LlamaIndexTextSplitter) -> None:

tests/e2e/weaviate_e2e/test_weaviate_e2e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ def test_weaviate_neo4j_text_input_remote_embedder(
131131
r"labels=frozenset\({'Question'}\) properties={'question': 'In 1953 Watson \& "
132132
"Crick built a model of the molecular structure of this, the gene-carrying "
133133
"substance', 'id': 'question_c458c6f64d8d47429636bc5a94c97f51'}> "
134-
r"score=0.5[0-9]+>"
134+
r"score=0.6[0-9]+>"
135135
)
136136
assert re.match(pattern, results.items[0].content)

0 commit comments

Comments
 (0)