Skip to content
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

Vector and Index Graph API improvements #1713

Closed
miratepuffin opened this issue Aug 14, 2024 · 0 comments
Closed

Vector and Index Graph API improvements #1713

miratepuffin opened this issue Aug 14, 2024 · 0 comments
Assignees
Labels
Enhancement New feature of request Semantics/API Changes to the way we interact with Raphtory or the results which are returned
Milestone

Comments

@miratepuffin
Copy link
Collaborator

miratepuffin commented Aug 14, 2024

For search APIs

#Currently we have to generate an IndexGraph via 
index = financial_graph.index()
#Instead I should be able to just call search_edges/search_nodes and internally if we have an index use that, if not create one
index.search_edges("from:Polux OR to:Hilux purpose:Payment")[3]

For vector APIs

#Current function call for vectorising - suggestion would be to change node_document and edge_document to functions which take node/edge and return List[Documents]
financial_graph.vectorise(lambda x: embeddings.embed_documents(x),node_document="document",edge_document="document",cache="embedding-cache-notebook",overwrite_cache=True)

Most functions below will error if the graph has hes to be vectorised - i.e. calling the function above

#Create a new empty selection context
selection = financial_graph.vector_context()
#Create context with 10 nodes (based on top 10 most similar documents, add all documents for each node)
selection2 = financial_graph.nodes_by_similarity("blah",10)
#Create context with 10 edges (based on top 10 most similar documents, add all documents for each edge)
selection3 = financial_graph.edges_by_similarity("blah",10)
#Create context with 10 nodes/edges (based on top 10 most similar documents, add all documents for each node/edge)
selection3 = financial_graph.entities_by_similarity("blah",10)
#Create context with 10 documents (based on top 10 most similar documents)
selection3 = financial_graph.documents_by_similarity("blah",10)

#Combine selections based on typical joins
selection.union(selection_2)
selection.intersection(selection_3)

#Add edges based on tantivty index search
index_search = financial_graph.search_edges("from:Polux OR to:Hilux purpose:Payment")
selection.add_edges(index_search)
#Can do same with node search/selction of nodes
selection.add_nodes(vec_of_nodes)

doc_list = []         #or .edges  
for doc in financial_graph.nodes.documents:
    #some filtering logic
    doc_list.append(doc)
# complex logic to decide specific documents to add
selection.add_documents(doc_list)

#top 10 ranked neighbours of nodes within the selection 
selection.expand_nodes_by_similarity("blah blah blah",10)
#top 10 ranked edges of nodes within the selection
selection.expand_edges_by_similarity("blah blah blah",10)
#top 10 ranked nodes/edges of nodes within the selection
selection.expand_by_similarity("blah blah blah",10)

selection.nodes() # -> Node objects from graph
selection.edges() # -> Edge objects from graph
selection.documents() # -> Document object which has reference to the content, the associated entity, the raw embedding 
selection.token_size() # -> how many tokens this context would be 

#Document attribute
document.entity
document.embedding
document.token_size # -> how many tokens the document is 
document.content
document.lifetime # -> the timerange for which this doc is valid
@miratepuffin miratepuffin added Semantics/API Changes to the way we interact with Raphtory or the results which are returned Enhancement New feature of request labels Aug 14, 2024
@miratepuffin miratepuffin added this to the 0.12.0 milestone Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature of request Semantics/API Changes to the way we interact with Raphtory or the results which are returned
Projects
None yet
Development

No branches or pull requests

2 participants