Skip to content

Introduce Graph Traversal—Dijkstra #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

Introduce Graph Traversal—Dijkstra #1922

wants to merge 6 commits into from

Conversation

NolanTrem
Copy link
Collaborator

@NolanTrem NolanTrem commented Jan 31, 2025

WIP

Introduces functionality to traverse graphs. Starting with Dijkstra, this allows for a request to be made indicating a source and target entity.

from r2r import R2RClient

client = R2RClient("http://localhost:7272")

response = client.graphs.dijkstra(
    collection_id="122fdf6a-e116-546b-a8f6-e4cb2e2c0a09",
    source_id="dbc89966-f1ce-5e23-9e5d-a78d45634b20", #John J. Hopfield
    target_id="0a963640-b787-46cc-97ef-276d486712d2" # Ronald Williams
)

print(response)

"""
{'results':
    {'path':
        [
            {'type': 'entity', 'id': 'dbc89966-f1ce-5e23-9e5d-a78d45634b20', 'name': None},
            {'type': 'relationship', 'id': 'e1f723fd-aa82-4254-968f-2841e9d528a4', 'predicate': 'Part Of', 'reversed': False, 'subject': 'Associative Memory Model', 'object': 'Artificial Neural Networks (ANNs)', 'weight': 8.0, 'cost': 8.0},
            {'type': 'relationship', 'id': '6b04c680-c551-4725-ab56-b0598fb5bdef', 'predicate': 'Utilizes', 'reversed': False, 'subject': 'Artificial Neural Networks (ANNs)', 'object': 'Backpropagation', 'weight': 8.0, 'cost': 8.0},
            {'type': 'relationship', 'id': 'f2924028-7d4e-435d-90aa-47c78dfe2daa', 'predicate': 'Contributed To', 'reversed': True, 'subject': 'Ronald Williams', 'object': 'Backpropagation', 'weight': 9.0, 'cost': 9.0}
        ],
        'total_cost': 16.0,
        'num_hops': 3
    }
}
"""

@NolanTrem NolanTrem closed this Mar 20, 2025
@NolanTrem NolanTrem deleted the Nolan/Dijkstra branch March 21, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant