VectorSelection#

class VectorSelection#

Bases: object

Methods:

add_edges(edges)

Add all the documents associated with the edges to the current selection

add_nodes(nodes)

Add all the documents associated with the nodes to the current selection

append(selection)

Add all the documents in selection to the current selection

edges()

Return the edges present in the current selection

expand(hops[, window])

Add all the documents hops hops away to the selection

expand_documents_by_similarity(query, limit)

Add the top limit adjacent documents with higher score for query to the selection

expand_edges_by_similarity(query, limit[, ...])

Add the top limit adjacent edges with higher score for query to the selection

expand_entities_by_similarity(query, limit)

Add the top limit adjacent entities with higher score for query to the selection

expand_nodes_by_similarity(query, limit[, ...])

Add the top limit adjacent nodes with higher score for query to the selection

get_documents()

Return the documents present in the current selection

get_documents_with_scores()

Return the documents alongside their scores present in the current selection

nodes()

Return the nodes present in the current selection

add_edges(edges)#

Add all the documents associated with the edges to the current selection

Documents added by this call are assumed to have a score of 0.

Parameters:

edges (list) – a list of the edge ids or edges to add

Return type:

None

add_nodes(nodes)#

Add all the documents associated with the nodes to the current selection

Documents added by this call are assumed to have a score of 0.

Parameters:

nodes (list) – a list of the node ids or nodes to add

Return type:

None

append(selection)#

Add all the documents in selection to the current selection

Parameters:

selection (VectorSelection) – a selection to be added

Returns:

The selection with the new documents

Return type:

VectorSelection

edges()#

Return the edges present in the current selection

Returns:

list of edges in the current selection

Return type:

list[Edge]

expand(hops, window=None)#

Add all the documents hops hops away to the selection

Two documents A and B are considered to be 1 hop away of each other if they are on the same entity or if they are on the same node/edge pair. Provided that, two nodes A and C are n hops away of each other if there is a document B such that A is n - 1 hops away of B and B is 1 hop away of C.

Parameters:
  • hops (int) – the number of hops to carry out the expansion

  • window (Tuple[int | str, int | str], optional) – the window where documents need to belong to in order to be considered

Return type:

None

expand_documents_by_similarity(query, limit, window=None)#

Add the top limit adjacent documents with higher score for query to the selection

The expansion algorithm is a loop with two steps on each iteration:
  1. All the documents 1 hop away of some of the documents included on the selection (and not already selected) are marked as candidates.

  2. Those candidates are added to the selection in descending order according to the similarity score obtained against the query.

This loops goes on until the current selection reaches a total of limit documents or until no more documents are available

Parameters:
  • query (str | list) – the text or the embedding to score against

  • limit (int) – the number of documents to add

  • window (Tuple[int | str, int | str], optional) – the window where documents need to belong to in order to be considered

Return type:

None

expand_edges_by_similarity(query, limit, window=None)#

Add the top limit adjacent edges with higher score for query to the selection

This function has the same behavior as expand_entities_by_similarity but it only considers edges.

Parameters:
  • query (str | list) – the text or the embedding to score against

  • limit (int) – the maximum number of new edges to add

  • window (Tuple[int | str, int | str], optional) – the window where documents need to belong to in order to be considered

Return type:

None

expand_entities_by_similarity(query, limit, window=None)#

Add the top limit adjacent entities with higher score for query to the selection

The expansion algorithm is a loop with two steps on each iteration:
  1. All the entities 1 hop away of some of the entities included on the selection (and not already selected) are marked as candidates.

  2. Those candidates are added to the selection in descending order according to the similarity score obtained against the query.

This loops goes on until the number of new entities reaches a total of limit entities or until no more documents are available

Parameters:
  • query (str | list) – the text or the embedding to score against

  • limit (int) – the number of documents to add

  • window (Tuple[int | str, int | str], optional) – the window where documents need to belong to in order to be considered

Return type:

None

expand_nodes_by_similarity(query, limit, window=None)#

Add the top limit adjacent nodes with higher score for query to the selection

This function has the same behavior as expand_entities_by_similarity but it only considers nodes.

Parameters:
  • query (str | list) – the text or the embedding to score against

  • limit (int) – the maximum number of new nodes to add

  • window (Tuple[int | str, int | str], optional) – the window where documents need to belong to in order to be considered

Return type:

None

get_documents()#

Return the documents present in the current selection

Returns:

list of documents in the current selection

Return type:

list[Document]

get_documents_with_scores()#

Return the documents alongside their scores present in the current selection

Returns:

list of documents and scores

Return type:

list[Tuple[Document, float]]

nodes()#

Return the nodes present in the current selection

Returns:

list of nodes in the current selection

Return type:

list[Node]