OpenSPG Documentation

repository·master·Indexed 24 days ago

https://github.com/openspg/openspg

OpenSPG is a knowledge graph engine based on the Semantic-enhanced Programmable Graph (SPG) framework, designed to bridge big data and AI. It provides core capabilities for semantic modeling via SPG-Schema, knowledge construction through SPG-Builder, and logical rule reasoning using SPG-Reasoner and KGDSL. The system includes a programmable framework (KNext) and a cloud adaptation layer (Cloudext) for integrating custom graph storage, computation engines, and search engine indices.

Tokens
2.7K
Snippets
1
Records
15
Agent score
81%

What's inside OpenSPG

  1. What is OpenSPG and the SPG Framework

    master

    OpenSPG is a knowledge graph engine based on the SPG (Semantic-enhanced Programmable Graph) framework. Developed by Ant Group and OpenKG, it combines the structural advantages of Labeled Property Graphs (LPG) with the semantic capabilities of RDF/OWL.

    Key characteristics of the SPG framework include:

    • Formalized Knowledge Representation: Defines knowledge in a way that is programmable and machine-understandable.
    • Hierarchical Compatibility: Supports incremental knowledge construction and continuous evolution, even with incomplete data.
    • Big Data & AI Integration: Bridges big data architectures with AI technologies to facilitate efficient knowledge conversion and high-value applications.
    • Extensibility: Allows users to quickly build domain-specific solutions by extending domain knowledge models and developing new operators.
  2. Core Capabilities of OpenSPG

    master

    OpenSPG provides a complete set of capabilities for domain knowledge graph construction and management through several core models:

    • SPG-Schema (Semantic Modeling): A schema framework for semantic enhancement of property graphs, including subject models, evolution models, and predicate models.
    • SPG-Builder (Knowledge Construction): Supports importing structured and unstructured knowledge. It provides an operator framework for converting data to knowledge and a knowledge processing SDK for tasks like entity linking, concept standardization, and entity normalization.
    • SPG-Reasoner (Logical Rule Reasoning): Uses KGDSL (Knowledge Graph Domain Specific Language) to provide programmable symbolic representations of logical rules. This supports rule reasoning, neuro-symbolic learning, and KG2Prompt integration with LLMs.
    • KNext (Programmable Framework): A component-based, extensible framework that isolates the engine from business logic and domain models, enabling a controllable AI technology stack (linking LLMs and Graph Learning).
    • Cloudext (Cloud Adaptation Layer): An SDK layer that allows businesses to connect to the engine, adapt custom graph storage/computation engines, and integrate specialized machine learning frameworks.
  3. Use IdxGetQuery to retrieve documents from a search engine index

    master
    The IdxGetQuery class is used to construct a query for retrieving specific documents from a search engine index. It requires the name of the target index and a set of document identifiers to fetch. This class extends BaseQuery and is part of the com.antgroup.openspg.cloudext.interfaces.searchengine.cmd package.
  4. Manipulate index records with IdxRecordManipulateCmd

    master

    The IdxRecordManipulateCmd is used to group and manage operations for altering index records within a search engine extension. It supports two primary operations: UPSERT (insert or update) and DELETE.

    When using this command, you provide a list of IdxRecordAlterItem objects. Each item specifies an operation type (RecordAlterOperationEnum) and the corresponding IdxRecord. The command allows you to retrieve these records grouped by their index name (idxName), which is useful for batch processing updates or deletions across different indices.

  5. Execute script-based LPG record queries

    master
    The ScriptLPGRecordQuery class is used to perform queries on a Labeled Property Graph (LPG) using a custom script. This is a specialized query type (LpgRecordQueryType.SCRIPT) that allows users to pass raw script strings to the graph store extension instead of using structured query parameters. The script is processed via the toScript method, which utilizes an LPGTypeNameConvertor to ensure type compatibility during execution.
  6. Batch vertex LPG record query

    master

    The BatchVertexLPGRecordQuery is used to generate a query for retrieving multiple vertex records from a Labeled Property Graph (LPG) store based on a set of vertex IDs and a specific vertex type name. It produces a Cypher-like Match script that filters vertices by their ID using an in clause.

    When using this query, the vertexName is processed through an LPGTypeNameConvertor to ensure the type name is compatible with the target graph store's syntax.

  7. Alter search engine index schema with IdxSchemaAlterCmd

    master

    The IdxSchemaAlterCmd is a command used to perform schema alterations on search engine indices. It encapsulates a list of IdxSchemaAlterItem objects, each specifying an operation and the corresponding index schema.

    Supported operations (via AlterOperationEnum) include:

    • CREATE: To create new indices.
    • UPDATE: To modify existing indices.
    • DELETE: To remove indices.

    You can retrieve grouped lists of schemas based on these operations using getCreateIdx(), getUpdateIdx(), and getDeleteIdx().

  8. Execute a one-hop LPG record query

    master

    The OneHopLPGRecordQuery class is used to construct queries for retrieving one-hop subgraphs from a Labeled Property Graph (LPG) store. It allows you to specify a source vertex, a set of edge types to traverse, and the direction of the traversal.

    Query Parameters

    • srcVertexId: The unique identifier of the source vertex.
    • srcVertexName: The type name of the source vertex.
    • edgeNames: A set of EdgeTypeName objects representing the types of edges to follow. If this set is empty or null, the query defaults to a VertexLPGRecordQuery (retrieving only the vertex itself).
    • direction: The direction of the traversal. Possible values are:
      • OUT: Traverses edges moving away from the source vertex.
      • IN: Traverses edges moving towards the source vertex.
      • BOTH: Traverses edges in both directions (defaults to this if no direction is provided).

    Generated Script Format

    The query is converted into a Cypher-like script via the toScript method using an LPGTypeNameConvertor. The resulting script follows this pattern:

    • OUT: MATCH (s:VertexType)-[p:EdgeType1|EdgeType2]->(o) WHERE s.id='ID' RETURN p;
    • IN: MATCH (s:VertexType)<-[p:EdgeType1|EdgeType2]-(o) WHERE s.id='ID' RETURN p;
    • BOTH: MATCH (s:VertexType)<-[p:EdgeType1|EdgeType2]->(o) WHERE s.id='ID' RETURN p;
  9. Query object vertex records via ObjectVertexRecordQuery

    master

    The ObjectVertexRecordQuery class is used to construct queries for retrieving object vertex records from a graph store. It generates a Cypher-like script based on a source vertex ID, a source vertex type name, a set of edge type names, and a traversal direction.

    Parameters

    • srcVertexId: The unique identifier of the source vertex.
    • srcVertexName: The type name of the source vertex (will be converted via LPGTypeNameConvertor).
    • edgeNames: A Set<EdgeTypeName> representing the types of edges to traverse. If empty, an IllegalArgumentException is thrown. If null, no edge type filter is applied.
    • direction: The direction of the traversal. Possible values are:
      • Direction.OUT: Traverses edges outgoing from the source vertex ((s)-[p]->(o)).
      • Direction.IN: Traverses edges incoming to the source vertex ((s)<-[p]-(o)).
      • Direction.BOTH: Traverses edges in both directions ((s)<-[p]->(o)). Defaults to BOTH if null is provided.

    Script Generation

    The toScript method uses an LPGTypeNameConvertor to ensure vertex and edge type names are correctly formatted for the target graph store. The resulting script follows a MATCH ... WHERE ... RETURN pattern.

  10. Scan LPG records via ScanLPGRecordQuery

    master

    The ScanLPGRecordQuery is used to generate query scripts for scanning Labeled Property Graph (LPG) records within a graph store extension. It supports scanning both vertices and edges by generating Cypher-like MATCH statements.

    Query Logic

    • For Edges: If the typeName is an instance of EdgeTypeName, it generates a query to match the relationship between the start and end vertex types: MATCH (s:StartType)-[p:EdgeType]->(o:EndType) RETURN p.
    • For Vertices: If the typeName is not an edge, it generates a query to match vertices of the specified type: MATCH (s:VertexType) RETURN s.
    • Limit: An optional limit can be applied to the end of the query using the LIMIT clause.
  11. Configure PageRank computation parameters

    master
    The PageRankCompete class defines the configuration for running PageRank computations within a graph store extension. It requires a list of starting vertices and a target vertex type. You can optionally tune the algorithm's convergence and execution behavior using parameters like dampingFactor, maxIterations, and parallel execution settings.