Skip to content

Commit

Permalink
using hook for selectedNodes and Relation (#995)
Browse files Browse the repository at this point in the history
  • Loading branch information
prakriti-solankey authored Jan 8, 2025
1 parent 5d0c8ec commit 1732f2f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 26 deletions.
8 changes: 4 additions & 4 deletions backend/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from src.graphDB_dataAccess import graphDBdataAccess
from src.graph_query import get_graph_results,get_chunktext_results
from src.chunkid_entities import get_entities_from_chunkids
from src.post_processing import create_vector_fulltext_indexes, create_entity_embedding, graph_cleanup
from src.post_processing import create_vector_fulltext_indexes, create_entity_embedding, graph_schema_consolidation
from sse_starlette.sse import EventSourceResponse
from src.communities import create_communities
from src.neighbours import get_neighbour_nodes
Expand Down Expand Up @@ -339,9 +339,9 @@ async def post_processing(uri=Form(), userName=Form(), password=Form(), database
api_name = 'post_processing/create_entity_embedding'
logging.info(f'Entity Embeddings created')

if "graph_cleanup" in tasks :
await asyncio.to_thread(graph_cleanup, graph)
api_name = 'post_processing/graph_cleanup'
if "graph_schema_consolidation" in tasks :
await asyncio.to_thread(graph_schema_consolidation, graph)
api_name = 'post_processing/graph_schema_consolidation'
logging.info(f'Updated nodes and relationship labels')

if "enable_communities" in tasks:
Expand Down
2 changes: 1 addition & 1 deletion backend/src/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def update_embeddings(rows, graph):
"""
return graph.query(query,params={'rows':rows})

def graph_cleanup(graph):
def graph_schema_consolidation(graph):
nodes_and_relations = get_labels_and_relationtypes(graph)
logging.info(f"nodes_and_relations in existing graph : {nodes_and_relations}")
node_labels = []
Expand Down
26 changes: 14 additions & 12 deletions frontend/src/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import PostProcessingToast from './Popups/GraphEnhancementDialog/PostProcessingC
import { getChunkText } from '../services/getChunkText';
import ChunkPopUp from './Popups/ChunkPopUp';
import { isExpired, isFileReadyToProcess } from '../utils/Utils';
import { useHasSelections } from '../hooks/useHasSelections';

const ConfirmationDialog = lazy(() => import('./Popups/LargeFilePopUp/ConfirmationDialog'));

Expand Down Expand Up @@ -105,6 +106,7 @@ const Content: React.FC<ContentProps> = ({
);
const [showDeletePopUp, setshowDeletePopUp] = useState<boolean>(false);
const [deleteLoading, setdeleteLoading] = useState<boolean>(false);
const hasSelections = useHasSelections(selectedNodes, selectedRels);

const { updateStatusForLargeFiles } = useServerSideEvent(
(inMinutes, time, fileName) => {
Expand Down Expand Up @@ -139,16 +141,16 @@ const Content: React.FC<ContentProps> = ({
<PostProcessingToast
isGdsActive={isGdsActive}
postProcessingTasks={postProcessingTasks}
isSchema={selectedNodes.length > 0 || selectedRels.length > 0}
isSchema={hasSelections}
/>
);
try {
const payload = isGdsActive
? selectedNodes.length > 0 || selectedRels.length > 0
? postProcessingTasks.filter((task) => task !== 'graph_cleanup')
? hasSelections
? postProcessingTasks.filter((task) => task !== 'graph_schema_consolidation')
: postProcessingTasks
: selectedNodes.length > 0 || selectedRels.length > 0
? postProcessingTasks.filter((task) => task !== 'graph_cleanup' && task !== 'enable_communities')
: hasSelections
? postProcessingTasks.filter((task) => task !== 'graph_schema_consolidation' && task !== 'enable_communities')
: postProcessingTasks.filter((task) => task !== 'enable_communities');
const response = await postProcessing(userCredentials as UserCredentials, payload);
if (response.data.status === 'Success') {
Expand Down Expand Up @@ -379,7 +381,7 @@ const Content: React.FC<ContentProps> = ({
const addFilesToQueue = async (remainingFiles: CustomFile[]) => {
if (!remainingFiles.length) {
showNormalToast(
<PostProcessingToast isGdsActive={isGdsActive} postProcessingTasks={postProcessingTasks} isSchema={selectedNodes.length > 0 || selectedRels.length > 0} />
<PostProcessingToast isGdsActive={isGdsActive} postProcessingTasks={postProcessingTasks} isSchema={hasSelections} />
);
try {
const response = await postProcessing(userCredentials as UserCredentials, postProcessingTasks);
Expand Down Expand Up @@ -704,7 +706,7 @@ const Content: React.FC<ContentProps> = ({
const selectedRows = childRef.current?.getSelectedRows();
if (selectedRows?.length) {
const expiredFilesExists = selectedRows.some(
(c) => c.status !== 'Ready to Reprocess' && isExpired(c?.createdAt as Date)
(c) => c.status !== 'Ready to Reprocess' && isExpired(c?.createdAt as Date ?? new Date())
);
const largeFileExists = selectedRows.some(
(c) => isFileReadyToProcess(c, true) && typeof c.size === 'number' && c.size > largeFileSize
Expand All @@ -718,7 +720,7 @@ const Content: React.FC<ContentProps> = ({
}
} else if (filesData.length) {
const expiredFileExists = filesData.some(
(c) => isExpired(c.createdAt as Date)
(c) => isExpired(c?.createdAt as Date)
);
const largeFileExists = filesData.some(
(c) => isFileReadyToProcess(c, true) && typeof c.size === 'number' && c.size > largeFileSize
Expand Down Expand Up @@ -847,17 +849,17 @@ const Content: React.FC<ContentProps> = ({
/>
<div className='pt-1 flex gap-1 items-center'>
<div>
{selectedNodes.length === 0 || selectedRels.length === 0 ? (
{!hasSelections ? (
<StatusIndicator type='danger' />
) :
(<StatusIndicator type='success' />
)}
</div>
<div>
{selectedNodes.length > 0 || selectedRels.length > 0 ? (
{hasSelections? (
<span className='n-body-small'>
{(!selectedNodes.length || !selectedRels.length) && 'Empty'} Graph Schema configured
{selectedNodes.length || selectedRels.length
{(hasSelections)} Graph Schema configured
{hasSelections
? `(${selectedNodes.length} Labels + ${selectedRels.length} Rel Types)`
: ''}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { OptionType, schema, UserCredentials } from '../../../../types';
import { getNodeLabelsAndRelTypes } from '../../../../services/GetNodeLabelsRelTypes';
import { tokens } from '@neo4j-ndl/base';
import { showNormalToast } from '../../../../utils/toasts';
import { useHasSelections } from '../../../../hooks/useHasSelections';

export default function EntityExtractionSetting({
view,
Expand Down Expand Up @@ -39,6 +40,7 @@ export default function EntityExtractionSetting({
const { userCredentials } = useCredentials();
const [loading, setLoading] = useState<boolean>(false);
const isTablet = useMediaQuery(`(min-width:${breakpoints.xs}) and (max-width: ${breakpoints.lg})`);
const hasSelections = useHasSelections(selectedNodes, selectedRels);
const removeNodesAndRels = (nodelabels: string[], relationshipTypes: string[]) => {
const labelsToRemoveSet = new Set(nodelabels);
const relationshipLabelsToremoveSet = new Set(relationshipTypes);
Expand Down Expand Up @@ -346,7 +348,7 @@ export default function EntityExtractionSetting({
placement='top'
onClick={handleClear}
label='Clear Graph Settings'
disabled={selectedNodes.length === 0 || selectedRels.length === 0}
disabled={!hasSelections}
>
{buttonCaptions.clearSettings}
</ButtonWithToolTip>
Expand All @@ -356,7 +358,7 @@ export default function EntityExtractionSetting({
placement='top'
onClick={handleApply}
label='Apply Graph Settings'
disabled={selectedNodes.length === 0 || selectedRels.length === 0}
disabled={!hasSelections}
>
{buttonCaptions.applyGraphSchema}
</ButtonWithToolTip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ export default function PostProcessingCheckList() {
<Flex justifyContent='space-between' flexDirection='column' gap='6'>
{POST_PROCESSING_JOBS.map((job, idx) => {
const isGraphCleanupDisabled =
job.title === 'graph_cleanup'
job.title === 'graph_schema_consolidation'
? !(selectedNodes.length === 0 && selectedRels.length === 0)
: false;
const isDisabled =
job.title === 'enable_communities'
? !isGdsActive
: job.title === 'graph_cleanup'
: job.title === 'graph_schema_consolidation'
? isGraphCleanupDisabled
: false;
const isChecked =
job.title === 'graph_cleanup'
job.title === 'graph_schema_consolidation'
? !isGraphCleanupDisabled && postProcessingTasks.includes(job.title)
: job.title === 'enable_communities'
? isGdsActive && postProcessingTasks.includes(job.title)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/context/UsersFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const FileContextProvider: FC<FileContextProviderProps> = ({ children }) => {
'enable_hybrid_search_and_fulltext_search_in_bloom',
'materialize_entity_similarities',
'enable_communities',
'graph_cleanup',
'graph_schema_consolidation',
]);
const [processedCount, setProcessedCount] = useState<number>(0);
const [postProcessingVal, setPostProcessingVal] = useState<boolean>(false);
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/hooks/useHasSelections.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useMemo } from "react";

import { OptionType } from "../types";
export const useHasSelections = (selectedNodes: readonly OptionType[], selectedRels: readonly OptionType[]) => {
const hasSelections = useMemo(()=> selectedNodes.length> 0 || selectedRels.length > 0,[selectedNodes, selectedRels]);
return hasSelections;
}
8 changes: 5 additions & 3 deletions frontend/src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export const llms =
'openai_gpt_4o_mini',
'gemini_1.5_pro',
'gemini_1.5_flash',
'gemini_2.0_flash',
'diffbot',
'azure_ai_gpt_35',
'azure_ai_gpt_4o',
'ollama_llama3',
'groq_llama3_70b',
'anthropic_claude_3_5_sonnet',
'fireworks_llama_v3p2_90b',
'fireworks_qwen72b_instruct',
'bedrock_claude_3_5_sonnet',
];

Expand Down Expand Up @@ -179,7 +181,7 @@ export const buttonCaptions = {
provideAdditionalInstructions: 'Provide Additional Instructions for Entity Extractions',
analyzeInstructions: 'Analyze Instructions',
helpInstructions:
'Provide specific instructions for entity extraction, such as focusing on key topics or excluding non-entity data like dates or revenues.',
'Provide specific instructions for entity extraction, such as focusing on the key topics.',
};

export const POST_PROCESSING_JOBS: { title: string; description: string }[] = [
Expand Down Expand Up @@ -209,8 +211,8 @@ export const POST_PROCESSING_JOBS: { title: string; description: string }[] = [
description: 'Enable community creation across entities to use GraphRAG capabilities both local and global search.',
},
{
title: 'graph_cleanup',
description: 'consolidate node-labels and rel-types and then update the graph ',
title: 'graph_schema_consolidation',
description: 'This option uses the LLM for large graph schemas to consolidate many node labels and relationship types into fewer, more relevant ones and apply it to the extracted and existing graph',
},
];
export const RETRY_OPIONS = [
Expand Down

0 comments on commit 1732f2f

Please sign in to comment.