Skip to content

Commit 437fc3d

Browse files
Merge branch 'main' of https://github.com/neo4j-labs/llm-graph-builder into staging
2 parents 02de002 + 9cde997 commit 437fc3d

File tree

16 files changed

+448
-14
lines changed

16 files changed

+448
-14
lines changed

backend/src/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from src.make_relationships import *
2525
from src.document_sources.web_pages import *
2626
from src.graph_query import get_graphDB_driver
27+
from src.graph_query import get_graphDB_driver
2728
import re
2829
from langchain_community.document_loaders import WikipediaLoader, WebBaseLoader
2930
import warnings
@@ -401,6 +402,7 @@ async def processing_source(uri, userName, password, database, model, file_name,
401402
obj_source_node.processing_time = processed_time
402403
obj_source_node.processed_chunk = select_chunks_upto+select_chunks_with_retry
403404
if retry_condition == START_FROM_BEGINNING:
405+
result = execute_graph_query(graph,QUERY_TO_GET_NODES_AND_RELATIONS_OF_A_DOCUMENT, params={"filename":file_name})
404406
result = execute_graph_query(graph,QUERY_TO_GET_NODES_AND_RELATIONS_OF_A_DOCUMENT, params={"filename":file_name})
405407
obj_source_node.node_count = result[0]['nodes']
406408
obj_source_node.relationship_count = result[0]['rels']
@@ -504,6 +506,10 @@ async def processing_chunks(chunkId_chunkDoc_list,graph,uri, userName, password,
504506
logging.info(f'Time taken to create relationship between chunk and entities: {elapsed_relationship:.2f} seconds')
505507
latency_processing_chunk["relationship_between_chunk_entity"] = f'{elapsed_relationship:.2f}'
506508

509+
graphDb_data_Access = graphDBdataAccess(graph)
510+
count_response = graphDb_data_Access.update_node_relationship_count(file_name)
511+
node_count = count_response[file_name].get('nodeCount',"0")
512+
rel_count = count_response[file_name].get('relationshipCount',"0")
507513
graphDb_data_Access = graphDBdataAccess(graph)
508514
count_response = graphDb_data_Access.update_node_relationship_count(file_name)
509515
node_count = count_response[file_name].get('nodeCount',"0")
@@ -530,6 +536,7 @@ def get_chunkId_chunkDoc_list(graph, file_name, pages, token_chunk_size, chunk_o
530536
else:
531537
chunkId_chunkDoc_list=[]
532538
chunks = execute_graph_query(graph,QUERY_TO_GET_CHUNKS, params={"filename":file_name})
539+
chunks = execute_graph_query(graph,QUERY_TO_GET_CHUNKS, params={"filename":file_name})
533540

534541
if chunks[0]['text'] is None or chunks[0]['text']=="" or not chunks :
535542
raise LLMGraphBuilderException(f"Chunks are not created for {file_name}. Please re-upload file and try again.")
@@ -541,11 +548,13 @@ def get_chunkId_chunkDoc_list(graph, file_name, pages, token_chunk_size, chunk_o
541548
if retry_condition == START_FROM_LAST_PROCESSED_POSITION:
542549
logging.info(f"Retry : start_from_last_processed_position")
543550
starting_chunk = execute_graph_query(graph,QUERY_TO_GET_LAST_PROCESSED_CHUNK_POSITION, params={"filename":file_name})
551+
starting_chunk = execute_graph_query(graph,QUERY_TO_GET_LAST_PROCESSED_CHUNK_POSITION, params={"filename":file_name})
544552

545553
if starting_chunk and starting_chunk[0]["position"] < len(chunkId_chunkDoc_list):
546554
return len(chunks), chunkId_chunkDoc_list[starting_chunk[0]["position"] - 1:]
547555

548556
elif starting_chunk and starting_chunk[0]["position"] == len(chunkId_chunkDoc_list):
557+
starting_chunk = execute_graph_query(graph,QUERY_TO_GET_LAST_PROCESSED_CHUNK_WITHOUT_ENTITY, params={"filename":file_name})
549558
starting_chunk = execute_graph_query(graph,QUERY_TO_GET_LAST_PROCESSED_CHUNK_WITHOUT_ENTITY, params={"filename":file_name})
550559
return len(chunks), chunkId_chunkDoc_list[starting_chunk[0]["position"] - 1:]
551560

@@ -725,6 +734,7 @@ def manually_cancelled_job(graph, filenames, source_types, merged_dir, uri):
725734
delete_uploaded_local_file(merged_file_path,file_name)
726735
return "Cancelled the processing job successfully"
727736

737+
def populate_graph_schema_from_text(text, model, is_schema_description_checked, is_local_storage):
728738
def populate_graph_schema_from_text(text, model, is_schema_description_checked, is_local_storage):
729739
"""_summary_
730740
@@ -738,6 +748,8 @@ def populate_graph_schema_from_text(text, model, is_schema_description_checked,
738748
"""
739749
result = schema_extraction_from_text(text, model, is_schema_description_checked, is_local_storage)
740750
return result
751+
result = schema_extraction_from_text(text, model, is_schema_description_checked, is_local_storage)
752+
return result
741753

742754
def set_status_retry(graph, file_name, retry_condition):
743755
graphDb_data_Access = graphDBdataAccess(graph)
@@ -750,6 +762,7 @@ def set_status_retry(graph, file_name, retry_condition):
750762
if retry_condition == DELETE_ENTITIES_AND_START_FROM_BEGINNING or retry_condition == START_FROM_BEGINNING:
751763
obj_source_node.processed_chunk=0
752764
if retry_condition == DELETE_ENTITIES_AND_START_FROM_BEGINNING:
765+
execute_graph_query(graph,QUERY_TO_DELETE_EXISTING_ENTITIES, params={"filename":file_name})
753766
execute_graph_query(graph,QUERY_TO_DELETE_EXISTING_ENTITIES, params={"filename":file_name})
754767
obj_source_node.node_count=0
755768
obj_source_node.relationship_count=0

backend/src/make_relationships.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from langchain_neo4j import Neo4jGraph
22
from langchain.docstore.document import Document
33
from src.shared.common_fn import load_embedding_model,execute_graph_query
4+
from src.shared.common_fn import load_embedding_model,execute_graph_query
45
import logging
56
from typing import List
67
import os
@@ -34,6 +35,7 @@ def merge_relationship_between_chunk_and_entites(graph: Neo4jGraph, graph_docume
3435
MERGE (c)-[:HAS_ENTITY]->(n)
3536
"""
3637
execute_graph_query(graph,unwind_query, params={"batch_data": batch_data})
38+
execute_graph_query(graph,unwind_query, params={"batch_data": batch_data})
3739

3840

3941
def create_chunk_embeddings(graph, chunkId_chunkDoc_list, file_name):
@@ -60,6 +62,7 @@ def create_chunk_embeddings(graph, chunkId_chunkDoc_list, file_name):
6062
MERGE (c)-[:PART_OF]->(d)
6163
"""
6264
execute_graph_query(graph,query_to_create_embedding, params={"fileName":file_name, "data":data_for_query})
65+
execute_graph_query(graph,query_to_create_embedding, params={"fileName":file_name, "data":data_for_query})
6366

6467
def create_relation_between_chunks(graph, file_name, chunks: List[Document])->list:
6568
logging.info("creating FIRST_CHUNK and NEXT_CHUNK relationships between chunks")
@@ -128,6 +131,7 @@ def create_relation_between_chunks(graph, file_name, chunks: List[Document])->li
128131
MERGE (c)-[:PART_OF]->(d)
129132
"""
130133
execute_graph_query(graph,query_to_create_chunk_and_PART_OF_relation, params={"batch_data": batch_data})
134+
execute_graph_query(graph,query_to_create_chunk_and_PART_OF_relation, params={"batch_data": batch_data})
131135

132136
query_to_create_FIRST_relation = """
133137
UNWIND $relationships AS relationship
@@ -137,6 +141,7 @@ def create_relation_between_chunks(graph, file_name, chunks: List[Document])->li
137141
MERGE (d)-[:FIRST_CHUNK]->(c))
138142
"""
139143
execute_graph_query(graph,query_to_create_FIRST_relation, params={"f_name": file_name, "relationships": relationships})
144+
execute_graph_query(graph,query_to_create_FIRST_relation, params={"f_name": file_name, "relationships": relationships})
140145

141146
query_to_create_NEXT_CHUNK_relation = """
142147
UNWIND $relationships AS relationship

frontend/src/components/ChatBot/ChunkInfo.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { handleGraphNodeClick } from './chatInfo';
1515
import { IconButtonWithToolTip } from '../UI/IconButtonToolTip';
1616
import remarkGfm from 'remark-gfm';
1717
import rehypeRaw from 'rehype-raw';
18+
1819
const ChunkInfo: FC<ChunkProps> = ({ loading, chunks, mode }) => {
1920
const themeUtils = useContext(ThemeWrapperContext);
2021
const [neoNodes, setNeoNodes] = useState<any[]>([]);

frontend/src/components/Graph/GraphPropertiesTable.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { GraphLabel, Typography } from '@neo4j-ndl/react';
22
import { GraphPropertiesTableProps } from '../../types';
33

44
const GraphPropertiesTable = ({ propertiesWithTypes }: GraphPropertiesTableProps): JSX.Element => {
5-
console.log('proerties', propertiesWithTypes);
65
return (
76
<div className='flex w-full flex-col break-all px-4 text-sm' data-testid='viz-details-pane-properties-table'>
87
<div className='mb-1 flex! flex-row pl-2'>

frontend/src/components/Layout/PageLayout.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const GCSModal = lazy(() => import('../DataSources/GCS/GCSModal'));
2828
const S3Modal = lazy(() => import('../DataSources/AWS/S3Modal'));
2929
const GenericModal = lazy(() => import('../WebSources/GenericSourceModal'));
3030
const ConnectionModal = lazy(() => import('../Popups/ConnectionModal/ConnectionModal'));
31-
3231
const spotlightsforunauthenticated = [
3332
{
3433
target: 'loginbutton',
@@ -92,7 +91,6 @@ const spotlightsforunauthenticated = [
9291
),
9392
},
9493
];
95-
9694
const spotlights = [
9795
{
9896
target: 'connectbutton',
@@ -147,7 +145,6 @@ const spotlights = [
147145
),
148146
},
149147
];
150-
151148
const PageLayout: React.FC = () => {
152149
const [openConnection, setOpenConnection] = useState<connectionState>({
153150
openPopUp: false,

frontend/src/utils/Utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,6 @@ export const generateGraphFromNodeAndRelVals = (
737737
): UserDefinedGraphSchema => {
738738
const schemeVal: Scheme = {};
739739
const uniqueNodesMap = new Map<string, ExtendedNode>();
740-
console.log('first rels', relVals);
741740
let nodeIdCounter = 0;
742741
nodeVals.forEach((node) => {
743742
const key = `${node.label}-${node.value}`;
@@ -792,7 +791,7 @@ export const generateGraphFromNodeAndRelVals = (
792791
type,
793792
});
794793
});
795-
console.log('new rels', transformedRelationships);
794+
796795
return {
797796
nodes: transformedNodes,
798797
relationships: transformedRelationships,

frontend/yarn.lock

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@
336336
resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-1.4.2.tgz#6df6c45881fcb1c412d6688a311a98b7f59c1b52"
337337
integrity sha512-3vLclRofFziIa3J2wDh9jjbkUz9qk5Vi3IZ/FSTKViB0k+ef0fPV7dYrUIugbgupYDx7v9ud/SjrtEP8Y4xLoA==
338338

339+
"@emotion/utils@^1.4.2":
340+
version "1.4.2"
341+
resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-1.4.2.tgz#6df6c45881fcb1c412d6688a311a98b7f59c1b52"
342+
integrity sha512-3vLclRofFziIa3J2wDh9jjbkUz9qk5Vi3IZ/FSTKViB0k+ef0fPV7dYrUIugbgupYDx7v9ud/SjrtEP8Y4xLoA==
343+
339344
"@emotion/weak-memoize@^0.4.0":
340345
version "0.4.0"
341346
resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.4.0.tgz#5e13fac887f08c44f76b0ccaf3370eb00fec9bb6"
@@ -3978,7 +3983,6 @@ gopd@^1.2.0:
39783983
resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.2.0.tgz#89f56b8217bdbc8802bd299df6d7f1081d7e51a1"
39793984
integrity sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==
39803985

3981-
39823986
graceful-fs@^4.2.4:
39833987
version "4.2.11"
39843988
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
@@ -4793,7 +4797,6 @@ levn@^0.4.1:
47934797
prelude-ls "^1.2.1"
47944798
type-check "~0.4.0"
47954799

4796-
47974800
47984801
version "1.29.1"
47994802
resolved "https://registry.yarnpkg.com/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.29.1.tgz#dce17349c7b9f968f396ec240503de14e7b4870b"
@@ -5713,7 +5716,6 @@ npm-run-path@^5.1.0:
57135716
integrity sha512-ppwTtiJZq0O/ai0z7yfudtBpWIoxM8yE6nHi1X47eFR2EWORqfbu6CnPlNsjeN683eT0qG6H/Pyf9fCcvjnnnQ==
57145717
dependencies:
57155718
path-key "^4.0.0"
5716-
57175719
57185720
version "0.2.1"
57195721
resolved "https://registry.yarnpkg.com/obj-case/-/obj-case-0.2.1.tgz#13a554d04e5ca32dfd9d566451fd2b0e11007f1a"
@@ -6719,10 +6721,7 @@ [email protected]:
67196721
resolved "https://registry.yarnpkg.com/sonner/-/sonner-1.7.1.tgz#737110a3e6211d8d766442076f852ddde1725205"
67206722
integrity sha512-b6LHBfH32SoVasRFECrdY8p8s7hXPDn3OHUFbZZbiB1ctLS9Gdh6rpX2dVrpQA0kiL5jcRzDDldwwLkSKk3+QQ==
67216723

6722-
source-map-js@^1.2.1:
6723-
version "1.2.1"
6724-
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.1.tgz#1ce5650fddd87abc099eda37dcff024c2667ae46"
6725-
integrity sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==
6724+
67266725

67276726
67286727
version "0.5.6"
@@ -7145,7 +7144,6 @@ typed-array-length@^1.0.7:
71457144
possible-typed-array-names "^1.0.0"
71467145
reflect.getprototypeof "^1.0.6"
71477146

7148-
71497147
typescript@^5.7.3:
71507148
version "5.7.3"
71517149
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.7.3.tgz#919b44a7dbb8583a9b856d162be24a54bf80073e"

0 commit comments

Comments
 (0)