Storage Operations

FalkorDB

Learn how to save your knowledge graph to a FalkorDB database.

See a working FalkorDB implementation example on GitHub.

The Perseus SDK provides a convenient method to save a KnowledgeGraph object directly to a FalkorDB database instance. This allows you to leverage the power of FalkorDB for graph visualization, complex queries, and further analysis.

Configuration

Before you can save a graph to FalkorDB, you need to configure the connection settings. The SDK uses environment variables or a .env file to manage these settings. For more details, refer to the Configuration guide.

The following parameters are required:

ParameterTypeDefault ValueDescription
FALKORDB_HOSTstrlocalhostThe host for your FalkorDB database connection.
FALKORDB_PORTstr6379The port for your FalkorDB database connection.
FALKORDB_USERNAMEstrNoneThe username for authenticating with FalkorDB.
FALKORDB_PASSWORDstrNoneThe password for authenticating with FalkorDB.
FALKORDB_GRAPH_NAMEstrperseus_graphThe graph name for your FalkorDB database.

Saving the Graph

Once your configuration is set up, you can use the save_to_falkordb() method on a KnowledgeGraph object to save it to your FalkorDB instance.

The save_to_falkordb() method saves the graph synchronously.

For more details on the save_to_falkordb method, refer to the Python API.

import perseus_client

knowledge_graphs = perseus_client.build_graph(
    file_paths=["assets/sample.txt"],
)

for kg in knowledge_graphs:
    kg.save_to_falkordb()

The save_to_falkordb_async() method saves the graph asynchronously.

For more details on the save_to_falkordb_async method, refer to the Python API.

import asyncio
import perseus_client

async def main():
    knowledge_graphs = await perseus_client.build_graph_async(
        file_paths=["assets/sample.txt"],
    )

    for kg in knowledge_graphs:
        await kg.save_to_falkordb_async()

if __name__ == "__main__":
    asyncio.run(main())