### Configuration Management Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/modules.md APIs for getting and setting FalkorDB configuration parameters. ```APIDOC ## Configuration Management ### Description Allows retrieval and modification of FalkorDB configuration settings. ### Methods - **`config_get(key: str)`**: Retrieves the value of a configuration key. - **`config_set(key: str, value: str)`**: Sets the value of a configuration key. ### Parameters #### `config_get` parameters: - **`key`** (str) - Required - The configuration key to retrieve. #### `config_set` parameters: - **`key`** (str) - Required - The configuration key to set. - **`value`** (str) - Required - The new value for the configuration key. ### Usage Example ```python from falkorddb import FalkorDB db = FalkorDB.from_url("bolt://neo4j:password@localhost:7687") # Get a configuration value page_cache_size = db.config_get("cache.page_size") print(f"Page cache size: {page_cache_size}") # Set a configuration value # db.config_set("query_timeout", "60000") # Set query timeout to 60 seconds ``` ### Response #### `config_get` Success Response: - **value** (str) - The current value of the configuration key. #### `config_set` Success Response: - **message** (str) - Confirmation message that the configuration was updated. ``` -------------------------------- ### Getting FalkorDB Configuration Settings Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.md The `config_get` method allows retrieval of database-level configuration parameters. This is useful for inspecting and understanding the current settings of the FalkorDB server. Refer to the FalkorDB documentation for a full list of configurable parameters. ```python class FalkorDB: # ... other methods ... def config_get(self, name: str) -> int | str: """Retrieve a DB level configuration.""" # Placeholder for actual implementation pass ``` -------------------------------- ### Install FalkorDB Python Client Source: https://github.com/falkordb/falkordb-py/blob/main/README.md Installs the FalkorDB Python client using pip. This is the primary way to add the library to your Python environment. ```shell pip install FalkorDB ``` -------------------------------- ### FalkorDB Database Configuration Management Source: https://context7.com/falkordb/falkordb-py/llms.txt Illustrates how to manage FalkorDB database configuration settings using the Python client. The example shows how to retrieve the current value of a configuration parameter like 'MAX_QUEUED_QUERIES' using `config_get()` and how to set a configuration parameter, such as 'QUERY_TIMEOUT', using `config_set()`. ```python from falkordb import FalkorDB db = FalkorDB(host='localhost', port=6379) # Get configuration value max_queued_queries = db.config_get('MAX_QUEUED_QUERIES') print(f"Max queued queries: {max_queued_queries}") # Set configuration value db.config_set('QUERY_TIMEOUT', 1000) print("Query timeout set to 1000ms") ``` -------------------------------- ### Call Procedures in FalkorDB with Python Source: https://context7.com/falkordb/falkordb-py/llms.txt Shows how to call built-in and custom procedures in FalkorDB using the Python client. Examples cover calling procedures without arguments, with arguments, and specifically the constraints procedure. It also demonstrates how to process the results returned by procedure calls. ```python from falkordb import FalkorDB db = FalkorDB(host='localhost', port=6379) graph = db.select_graph('social') # Call procedure without arguments result = graph.call_procedure('DB.INDEXES', read_only=True) for row in result.result_set: print(f"Index: {row}") # Call procedure with arguments result = graph.call_procedure( 'DB.IDX.FULLTEXT.QUERYNODE', args=['Person', 'search term'], emit=['node', 'score'], read_only=True ) for row in result.result_set: node = row[0] score = row[1] print(f"Node: {node.properties}, Score: {score}") # Call constraints procedure constraints = graph.call_procedure('DB.CONSTRAINTS', read_only=True) for row in constraints.result_set: print(f"Constraint: {row}") ``` -------------------------------- ### Manage FalkorDB Configuration Asynchronously (Python) Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Provides asynchronous functions to get and set database-level configurations in FalkorDB. These functions allow dynamic adjustment of server settings. ```python config_value = await db.config_get("name_of_config") await db.config_set("name_of_config", "new_value") ``` -------------------------------- ### Asynchronous FalkorDB Operations in Python Source: https://github.com/falkordb/falkordb-py/blob/main/README.md Provides an example of asynchronous operations with FalkorDB using the Python client and asyncio. It shows how to establish an asynchronous connection, execute single queries, and run multiple queries concurrently. ```python import asyncio from falkordb.asyncio import FalkorDB from redis.asyncio import BlockingConnectionPool async def main(): # Connect to FalkorDB pool = BlockingConnectionPool(max_connections=16, timeout=None, decode_responses=True) db = FalkorDB(connection_pool=pool) # Select the social graph g = db.select_graph('social') # Execute query asynchronously result = await g.query('UNWIND range(0, 100) AS i CREATE (n {v:1}) RETURN n LIMIT 10') # Process results for n in result.result_set: print(n) # Run multiple queries concurrently tasks = [ g.query('MATCH (n) WHERE n.v = 1 RETURN count(n) AS count'), g.query('CREATE (p:Person {name: "Alice"}) RETURN p'), g.query('CREATE (p:Person {name: "Bob"}) RETURN p') ] results = await asyncio.gather(*tasks) # Process concurrent results print(f"Node count: {results[0].result_set[0][0]}") print(f"Created Alice: {results[1].result_set[0][0]}") print(f"Created Bob: {results[2].result_set[0][0]}") # Close the connection when done await pool.aclose() # Run the async example if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Connecting to FalkorDB with Python Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.md The `FalkorDB` class is the primary interface for interacting with a FalkorDB server. It supports various connection parameters, including host, port, authentication, and SSL configuration. The example demonstrates connecting to the database and selecting a graph. ```python from falkordb import FalkorDB # connect to the database and select the ‘social’ graph db = FalkorDB() graph = db.select_graph(“social”) # get a single ‘Person’ node from the graph and print its name # Assuming a query method exists and returns a result_set structure # result = graph.query(“MATCH (n:Person) RETURN n LIMIT 1”).result_set # person = result[0][0] # print(person.properties[‘name’]) ``` -------------------------------- ### Create Relationships Between Nodes (Python) Source: https://context7.com/falkordb/falkordb-py/llms.txt Provides an example of how to create relationships between existing nodes in FalkorDB. This snippet is intended to show the basic structure for relationship creation. Requires the `falkordb` library. ```python from falkordb import FalkorDB db = FalkorDB(host='localhost', port=6379) graph = db.select_graph('social') # Example: MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) CREATE (a)-[:KNOWS]->(b) ``` -------------------------------- ### Run FalkorDB Instance with Docker Source: https://github.com/falkordb/falkordb-py/blob/main/README.md Starts a FalkorDB instance using Docker. This command maps the default FalkorDB port (6379) from the container to the host machine, making it accessible. ```shell docker run --rm -p 6379:6379 falkordb/falkordb ``` -------------------------------- ### Query and Traverse Graph Paths with Python Source: https://context7.com/falkordb/falkordb-py/llms.txt Illustrates how to query and traverse graph paths using the FalkorDB Python client. This includes a Cypher query to find paths between nodes and code to process the path results, such as iterating through nodes and edges, and accessing the start and end nodes of a path. ```python from falkordb import FalkorDB db = FalkorDB(host='localhost', port=6379) graph = db.select_graph('social') # Find paths between nodes result = graph.query(''' MATCH path = (a:Person {name: 'Alice'})-[:KNOWS*1..3]->(b:Person {name: 'David'}) RETURN path LIMIT 5 ''') # Process path results for row in result.result_set: path = row[0] print(f"Path has {path.node_count()} nodes and {path.edge_count()} edges") # Iterate through path for i in range(path.node_count()): node = path.get_node(i) print(f" Node {i}: {node.properties.get('name', 'unnamed')}") if i < path.edge_count(): edge = path.get_edge(i) print(f" Edge {i}: {edge.relation}") # Get first and last nodes print(f"Start: {path.first_node().properties}") print(f"End: {path.last_node().properties}") ``` -------------------------------- ### FalkorDB Graph Management: Copying and Deleting Graphs Source: https://context7.com/falkordb/falkordb-py/llms.txt Provides guidance on managing graphs within FalkorDB using the Python client. It demonstrates how to list all available graphs, select a specific graph to work with, create a copy of a graph for backup or testing purposes, and delete a graph. The example retrieves node counts before copying and confirms deletion. ```python from falkordb import FalkorDB db = FalkorDB(host='localhost', port=6379) # List all graphs graphs = db.list_graphs() print(f"Existing graphs: {graphs}") # Select and work with a graph graph = db.select_graph('production') result = graph.query('MATCH (n) RETURN count(n) as node_count') node_count = result.result_set[0][0] print(f"Production graph has {node_count} nodes") # Create a copy for testing test_graph = graph.copy('test_backup') print(f"Created backup graph: {test_graph.name}") # Delete the test graph test_graph.delete() print("Backup graph deleted") ``` -------------------------------- ### FalkorDB Client Initialization Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/modules.md This section covers how to initialize the FalkorDB client and connect to a database instance. ```APIDOC ## FalkorDB Client Initialization ### Description Initializes a connection to the FalkorDB database. ### Method `FalkorDB.from_url(url: str, read_only: bool = False, username: str = 'admin', password: str = 'password', verify_ssl: bool = True, custom_auth_header: str = None)` ### Endpoint N/A (Client-side initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from falkordb import FalkorDB db = FalkorDB.from_url("bolt://neo4j:password@localhost:7687") ``` ### Response #### Success Response (200) - **db** (FalkorDB) - An initialized FalkorDB client instance. #### Response Example ```json { "message": "Successfully connected to FalkorDB" } ``` ``` -------------------------------- ### Execute Write Queries with Parameters (Python) Source: https://context7.com/falkordb/falkordb-py/llms.txt Illustrates how to execute write queries (like CREATE) with parameters to prevent injection vulnerabilities and improve readability. It also shows how to access query results and statistics. Requires the `falkordb` library. ```python from falkordb import FalkorDB db = FalkorDB(host='localhost', port=6379) graph = db.select_graph('users') # Create nodes with parameterized query params = { 'name': 'Alice', 'age': 30, 'city': 'New York' } result = graph.query( 'CREATE (p:Person {name: $name, age: $age, city: $city}) RETURN p', params=params ) # Access results for row in result.result_set: person = row[0] print(f"Created: {person.properties['name']}") # Check statistics print(f"Nodes created: {result.nodes_created}") print(f"Properties set: {result.properties_set}") print(f"Execution time: {result.run_time_ms}ms") ``` -------------------------------- ### Initialize FalkorDB Async Client from URL (Python) Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Shows how to create a FalkorDB asynchronous client instance by providing a connection URL. This method supports various URL schemes including 'falkor://', 'falkors://', and 'unix://'. ```python db = FalkorDB.from_url("falkor://[[username]:[password]]@localhost:6379") db = FalkorDB.from_url("falkors://[[username]:[password]]@localhost:6379") db = FalkorDB.from_url("unix://[username@]/path/to/socket.sock?db=0[&password=password]") ``` -------------------------------- ### Get Graph Name (Python) Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.md Retrieves the name of the currently connected graph. This is a simple property accessor that returns the graph's identifier as a string. ```python graph_name = falkordb_client.name ``` -------------------------------- ### Initialize FalkorDB Async Client and Select Graph (Python) Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Demonstrates how to initialize the asynchronous FalkorDB client and select a specific graph for operations. This involves creating an instance of FalkorDB and then using the select_graph method. ```python from falkordb.asyncio import FalkorDB # connect to the database and select the ‘social’ graph db = FalkorDB() graph = db.select_graph("social") # get a single ‘Person’ node from the graph and print its name response = await graph.query("MATCH (n:Person) RETURN n LIMIT 1") result = response.result_set person = result[0][0] print(node.properties['name']) ``` -------------------------------- ### falkordb.edge.Edge Class Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.md Represents an edge connecting two nodes in the FalkorDB graph. Includes a method to get a string representation of the edge's properties. ```APIDOC ## falkordb.edge.Edge Class ### Description An edge connecting two nodes. ### Methods #### to_string() -> str Get a string representation of the edge’s properties. Returns: : str: A string representation of the edge’s properties. ``` -------------------------------- ### Get FalkorDB Relationship by Index Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Retrieves a relationship type from the FalkorDB graph schema using its index. This function is useful for identifying relationship types by their numerical identifier. ```python async def get_relation(idx: int) -> str: """Returns a relationship type by its index. Args: idx (int): The index of the relation. Returns: str: The relationship type. """ pass ``` -------------------------------- ### Get FalkorDB Label by Index Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Retrieves a node label from the FalkorDB graph schema using its index. This function is part of schema introspection and requires the index of the label. ```python async def get_label(idx: int) -> str: """Returns a label by its index. Args: idx (int): The index of the label. Returns: str: The label. """ pass ``` -------------------------------- ### Connect to FalkorDB and Select Graph (Python) Source: https://context7.com/falkordb/falkordb-py/llms.txt Demonstrates how to connect to a FalkorDB instance using different methods (host/port, authentication, URL) and then select a specific graph to work with. Requires the `falkordb` library. ```python from falkordb import FalkorDB # Connect to local FalkorDB instance db = FalkorDB(host='localhost', port=6379) # Or connect with authentication db = FalkorDB(host='localhost', port=6379, password='mypassword') # Or connect using URL db = FalkorDB.from_url("falkor://username:password@localhost:6379") # Select a graph to work with graph = db.select_graph('social') ``` -------------------------------- ### Get Query Execution Plan in FalkorDB Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Retrieves the execution plan for a given query asynchronously. This is useful for understanding query performance and optimizing queries. It returns an ExecutionPlan object. ```python async def explain(query: str, params=None) -> [ExecutionPlan](falkordb.md#falkordb.execution_plan.ExecutionPlan): """Get the execution plan for a given query. GRAPH.EXPLAIN returns an ExecutionPlan object. See: https://docs.falkordb.com/commands/graph.explain.html Args: query (str): The query for which to get the execution plan. params (dict): Query parameters. Returns: ExecutionPlan: The execution plan. """ pass ``` -------------------------------- ### FalkorDB Client Configuration API Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.md Manage database-level configurations and create FalkorDB instances from a URL. ```APIDOC ## POST /falkordb/config_set ### Description Updates a database-level configuration parameter. ### Method POST ### Endpoint `/falkordb/config_set` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (str) - Required - The name of the configuration to update. - **value** (any) - Optional - The new value for the configuration. ### Request Example ```json { "name": "graph_dialects", "value": "CYPHER" } ``` ### Response #### Success Response (200) - **status** (str) - Indicates success or failure of the operation. #### Response Example ```json { "status": "success" } ``` ## Class Method: FalkorDB.from_url ### Description Creates a new FalkorDB instance by connecting to a database using a provided URL. ### Method POST ### Endpoint `/falkordb/from_url` ### Parameters #### Path Parameters None #### Query Parameters - **url** (str) - Required - The connection URL for the FalkorDB instance. - **kwargs** (dict) - Optional - Additional keyword arguments to pass to the connection function. ### Request Example ```json { "url": "falkordb://[[username]:[password]]@localhost:6379", "kwargs": { "timeout": 5 } } ``` ### Response #### Success Response (200) - **db_instance** (object) - A new FalkorDB instance. #### Response Example ```json { "db_instance": "" } ``` ``` -------------------------------- ### Represent a FalkorDB Node Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.md Defines the `Node` class for representing individual nodes within a FalkorDB graph. It allows specifying node ID, alias, labels, and properties, and provides a method to get a string representation of its properties. ```python from falkordb.node import Node # Create a node with properties person_node = Node(node_id=1, labels='Person', properties={'name': 'Alice', 'age': 30}) # Get a string representation of the node's properties print(person_node.to_string()) # Create a node without an ID (for insertion) new_node = Node(labels=['Movie', 'Hogwarts'], properties={'title': 'Inception', 'year': 2010}) print(new_node.labels) print(new_node.properties) ``` -------------------------------- ### Create Nodes with Labels and Properties (Python) Source: https://context7.com/falkordb/falkordb-py/llms.txt Demonstrates how to create nodes in FalkorDB, assigning multiple labels and properties to them. It shows both using a direct query and creating a `Node` object first. Requires the `falkordb` library. ```python from falkordb import FalkorDB, Node db = FalkorDB(host='localhost', port=6379) graph = db.select_graph('knowledge') # Create a node object node = Node( labels=['Person', 'Employee'], properties={'name': 'Bob', 'age': 35, 'department': 'Engineering'} ) # Use in query result = graph.query( 'CREATE (p:Person:Employee {name: $name, age: $age, dept: $dept}) RETURN p', params={'name': 'Bob', 'age': 35, 'dept': 'Engineering'} ) created_node = result.result_set[0][0] print(f"Node ID: {created_node.id}") print(f"Labels: {created_node.labels}") print(f"Properties: {created_node.properties}") ``` -------------------------------- ### Get FalkorDB Property by Index Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Retrieves a property key from the FalkorDB graph schema using its index. This function aids in schema exploration by accessing properties via their numerical index. ```python async def get_property(idx: int) -> str: """Returns a property by its index. Args: idx (int): The index of the property. Returns: str: The property. """ pass ``` -------------------------------- ### Node Index Creation API Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md APIs for creating different types of indexes on nodes. ```APIDOC ## POST /falkordb-py/node/index/fulltext ### Description Creates a full-text index for a node label. ### Method POST ### Endpoint /falkordb-py/node/index/fulltext ### Parameters #### Path Parameters None #### Query Parameters * **label** (str) - Required - The label of the node. * **properties** (list of str) - Required - Variable number of property names to be indexed. ### Request Body None ### Request Example ```json { "label": "User", "properties": ["username", "email"] } ``` ### Response #### Success Response (200) - **result** (object) - The result of the index creation query. #### Response Example ```json { "result": "Index created successfully" } ``` --- ## POST /falkordb-py/node/index/range ### Description Creates a range index for a node label. ### Method POST ### Endpoint /falkordb-py/node/index/range ### Parameters #### Path Parameters None #### Query Parameters * **label** (str) - Required - The label of the node. * **properties** (list of str) - Required - Variable number of property names to be indexed. ### Request Body None ### Request Example ```json { "label": "Product", "properties": ["price", "rating"] } ``` ### Response #### Success Response (200) - **result** (object) - The result of the index creation query. #### Response Example ```json { "result": "Index created successfully" } ``` --- ## POST /falkordb-py/node/index/vector ### Description Creates a vector index for a node label. ### Method POST ### Endpoint /falkordb-py/node/index/vector ### Parameters #### Path Parameters None #### Query Parameters * **label** (str) - Required - The label of the node. * **properties** (list of str) - Required - Variable number of property names to be indexed. * **dim** (int, optional) - The dimension of the vector. Defaults to 0. * **similarity_function** (str, optional) - The similarity function for the vector. Defaults to 'euclidean'. ### Request Body None ### Request Example ```json { "label": "Document", "properties": ["embedding"], "dim": 1536, "similarity_function": "cosine" } ``` ### Response #### Success Response (200) - **result** (object) - The result of the index creation query. #### Response Example ```json { "result": "Index created successfully" } ``` ``` -------------------------------- ### Get FalkorDB Slow Query Log Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Retrieves a list of up to 10 slowest queries executed against the FalkorDB graph. Each log entry includes timestamp, command, query, and execution time. ```python async def slowlog() -> List: """Get a list containing up to 10 of the slowest queries issued against the graph. Each item in the list has the following structure: 1. a unix timestamp at which the log entry was processed 2. the issued command 3. the issued query 4. the amount of time needed for its execution, in milliseconds. See: https://docs.falkordb.com/commands/graph.slowlog.html Returns: List: List of slow log entries. """ pass ``` -------------------------------- ### Explain Query Execution Plan (Python) Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.md Retrieves the execution plan for a given query without executing it. This is invaluable for understanding query performance and identifying potential bottlenecks. It returns an ExecutionPlan object. ```python falkordb_client.explain("MATCH (n) RETURN n", params={'limit': 10}) ``` -------------------------------- ### FalkorDB Query Profiling and Optimization with Python Source: https://context7.com/falkordb/falkordb-py/llms.txt Details how to profile and optimize query execution in FalkorDB using the Python client. This includes generating query execution plans without running the query using `explain()`, profiling queries with actual execution metrics using `profile()`, and inspecting the slowlog for optimization opportunities. Resetting the slowlog is also demonstrated. ```python from falkordb import FalkorDB db = FalkorDB(host='localhost', port=6379) graph = db.select_graph('analytics') # Get execution plan without running query plan = graph.explain('MATCH (p:Person)-[:KNOWS*2..3]->(f) RETURN p, f') print("Execution Plan:") for operation in plan.operations: print(f" {operation}") # Profile query with actual execution metrics profile = graph.profile( 'MATCH (p:Person)-[:KNOWS*2..3]->(f) WHERE p.age > $age RETURN p.name, f.name', params={'age': 25} ) print("\nProfile Results:") for operation in profile.operations: print(f" Operation: {operation}") # Check slowlog for query optimization slowlog = graph.slowlog() for entry in slowlog: timestamp, command, query, duration_ms = entry print(f"Query: {query}") print(f"Duration: {duration_ms}ms") print(f"Timestamp: {timestamp}") # Reset slowlog graph.slowlog_reset() ``` -------------------------------- ### Asynchronous Connection and Query Execution with Pooling (Python) Source: https://context7.com/falkordb/falkordb-py/llms.txt Shows how to establish an asynchronous connection to FalkorDB using a connection pool, execute queries, and properly close the pool. This is useful for high-concurrency applications. Requires `falkordb.asyncio` and `redis.asyncio`. ```python import asyncio from falkordb.asyncio import FalkorDB from redis.asyncio import BlockingConnectionPool async def main(): # Create connection pool pool = BlockingConnectionPool( max_connections=16, timeout=None, decode_responses=True ) # Connect to FalkorDB db = FalkorDB(connection_pool=pool) # Select graph graph = db.select_graph('social') # Execute async query result = await graph.query('MATCH (n) RETURN n LIMIT 10') # Close connection pool await pool.aclose() asyncio.run(main()) ``` -------------------------------- ### Edge Index Creation API Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md APIs for creating different types of indexes on edges. ```APIDOC ## POST /falkordb-py/edge/index/fulltext ### Description Creates a full-text index for an edge relation. ### Method POST ### Endpoint /falkordb-py/edge/index/fulltext ### Parameters #### Path Parameters None #### Query Parameters * **relation** (str) - Required - The relation of the edge. * **properties** (list of str) - Required - Variable number of property names to be indexed. ### Request Body None ### Request Example ```json { "relation": "REVIEWED", "properties": ["review_text", "rating"] } ``` ### Response #### Success Response (200) - **result** (object) - The result of the index creation query. #### Response Example ```json { "result": "Index created successfully" } ``` --- ## POST /falkordb-py/edge/index/range ### Description Creates a range index for an edge relation. ### Method POST ### Endpoint /falkordb-py/edge/index/range ### Parameters #### Path Parameters None #### Query Parameters * **relation** (str) - Required - The relation of the edge. * **properties** (list of str) - Required - Variable number of property names to be indexed. ### Request Body None ### Request Example ```json { "relation": "PURCHASED", "properties": ["purchase_date", "quantity"] } ``` ### Response #### Success Response (200) - **result** (object) - The result of the index creation query. #### Response Example ```json { "result": "Index created successfully" } ``` --- ## POST /falkordb-py/edge/index/vector ### Description Creates a vector index for an edge relation. ### Method POST ### Endpoint /falkordb-py/edge/index/vector ### Parameters #### Path Parameters None #### Query Parameters * **relation** (str) - Required - The relation of the edge. * **properties** (list of str) - Required - Variable number of property names to be indexed. * **dim** (int, optional) - The dimension of the vector. Defaults to 0. * **similarity_function** (str, optional) - The similarity function for the vector. Defaults to 'euclidean'. ### Request Body None ### Request Example ```json { "relation": "SIMILAR_ITEM", "properties": ["vector"], "dim": 768, "similarity_function": "dot_product" } ``` ### Response #### Success Response (200) - **result** (object) - The result of the index creation query. #### Response Example ```json { "result": "Index created successfully" } ``` ``` -------------------------------- ### Create Nodes and Relationships in FalkorDB Source: https://context7.com/falkordb/falkordb-py/llms.txt Demonstrates how to create nodes with properties and relationships with properties between them using the FalkorDB Python client. It also shows how to retrieve and print properties of the created elements. ```python from falkordb import FalkorDB db = FalkorDB(host='localhost', port=6379) graph = db.select_graph('social') # Create single property index on node graph.create_node_range_index('Person', 'name') # Create composite index on multiple properties graph.create_node_range_index('Person', 'age', 'city') # Create index on edge relationship graph.create_edge_range_index('KNOWS', 'since') # List all indexes indices = graph.list_indices() for idx in indices.result_set: print(f"Index: {idx}") ``` -------------------------------- ### List and Select Graphs Asynchronously (Python) Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Demonstrates how to retrieve a list of all available graph names and how to select a specific graph for subsequent operations using the FalkorDB asynchronous client. ```python graph_names = await db.list_graphs() selected_graph = db.select_graph("my_graph") ``` -------------------------------- ### Create Node Vector Index (Python) Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Creates a vector index for a node with specified properties and similarity function. Requires the node label, property names, vector dimension, and an optional similarity function. Returns the result of the index creation query. ```python async def create_node_vector_index(label: str, *properties, dim: int = 0, similarity_function: str = 'euclidean') -> QueryResult: """Create a vector index for a node. See: https://docs.falkordb.com/commands/graph.query.html#vector-indexing """ pass ``` -------------------------------- ### Call Procedure and Copy Graph Asynchronously (Python) Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Illustrates how to asynchronously call stored procedures within a graph and how to create a copy of an existing graph using the AsyncGraph object. ```python procedure_result = await graph.call_procedure("my_procedure", args=["arg1", 123]) cloned_graph = await graph.copy("cloned_graph_name") ``` -------------------------------- ### Manage FalkorDB UDFs with Python Source: https://context7.com/falkordb/falkordb-py/llms.txt Demonstrates how to define, load, list, and delete User Defined Functions (UDFs) using the FalkorDB Python client. This includes loading UDFs with and without replacement, listing UDFs with and without their code, and deleting specific UDF libraries or flushing all UDFs. ```python from falkordb import FalkorDB db = FalkorDB(host='localhost', port=6379) # Define UDF script udf_script = """ function my_custom_function(arg1, arg2) { return arg1 + arg2; } """ # Load UDF db.udf_load('my_lib', udf_script) # Load UDF and replace if exists db.udf_load('my_lib', udf_script, replace=True) # List all UDFs udfs = db.udf_list() print(f"Available UDFs: {udfs}") # List specific UDF with code udf_details = db.udf_list(lib='my_lib', with_code=True) print(f"UDF Details: {udf_details}") # Delete UDF db.udf_delete('my_lib') # Flush all UDFs db.udf_flush() ``` -------------------------------- ### Node Constraint Creation API Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md APIs for creating different types of constraints on nodes. ```APIDOC ## POST /falkordb-py/node/constraint/mandatory ### Description Creates a mandatory constraint for a node label. ### Method POST ### Endpoint /falkordb-py/node/constraint/mandatory ### Parameters #### Path Parameters None #### Query Parameters * **label** (str) - Required - Node label to apply constraint to. * **properties** (list of str) - Required - Variable number of property names to constrain. ### Request Body None ### Request Example ```json { "label": "User", "properties": ["username", "password"] } ``` ### Response #### Success Response (200) - **result** (str) - A message indicating the constraint creation status. #### Response Example ```json { "result": "Constraint creation initiated" } ``` --- ## POST /falkordb-py/node/constraint/unique ### Description Creates a unique constraint for a node label. This requires an existing range index over the constraint properties. ### Method POST ### Endpoint /falkordb-py/node/constraint/unique ### Parameters #### Path Parameters None #### Query Parameters * **label** (str) - Required - Node label to apply constraint to. * **properties** (list of str) - Required - Variable number of property names to constrain. ### Request Body None ### Request Example ```json { "label": "User", "properties": ["email"] } ``` ### Response #### Success Response (200) - **result** (str) - A message indicating the constraint creation status. #### Response Example ```json { "result": "Constraint creation initiated" } ``` ``` -------------------------------- ### Working with Paths Source: https://context7.com/falkordb/falkordb-py/llms.txt Query and traverse graph paths using Cypher queries. ```APIDOC ## Working with Paths ### Query Paths Executes a Cypher query to find and return paths within the graph. ### Method POST ### Endpoint `/graph/{graph_name}/query` ### Parameters #### Path Parameters - **graph_name** (string) - Required - The name of the graph to query. #### Request Body - **query** (string) - Required - The Cypher query string, which should include a `RETURN path` clause. ### Request Example ```json { "query": "MATCH path = (a:Person {name: 'Alice'})-[:KNOWS*1..3]->(b:Person {name: 'David'}) RETURN path LIMIT 5" } ``` ### Response #### Success Response (200) - **result_set** (array) - An array of path objects. Each path object contains nodes and edges. #### Path Object Structure - **node_count** (integer) - The number of nodes in the path. - **edge_count** (integer) - The number of edges in the path. - **nodes** (array) - An array of node objects within the path. - **edges** (array) - An array of edge objects within the path. #### Node Object Structure - **@type** (string) - "node" - **id** (integer) - Node ID. - **labels** (array) - Node labels. - **properties** (object) - Node properties. #### Edge Object Structure - **@type** (string) - "edge" - **id** (integer) - Edge ID. - **source** (integer) - ID of the source node. - **target** (integer) - ID of the target node. - **relation** (string) - Type of the relationship. - **properties** (object) - Edge properties. ### Response Example ```json { "result_set": [ { "@type": "path", "node_count": 3, "edge_count": 2, "nodes": [ { "@type": "node", "id": 1, "labels": ["Person"], "properties": {"name": "Alice"} }, { "@type": "node", "id": 2, "labels": ["Person"], "properties": {"name": "Bob"} }, { "@type": "node", "id": 3, "labels": ["Person"], "properties": {"name": "David"} } ], "edges": [ { "@type": "edge", "id": 10, "source": 1, "target": 2, "relation": "KNOWS", "properties": {} }, { "@type": "edge", "id": 11, "source": 2, "target": 3, "relation": "KNOWS", "properties": {} } ] } ] } ``` ``` -------------------------------- ### Managing Execution Plans in FalkorDB Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.md The `ExecutionPlan` class represents a collection of operations in FalkorDB. It allows for collecting operations by name and provides access to a structured tree of operations. Each `Operation` within the plan has attributes for its name, arguments, children, and profiling statistics. ```python class Operation: def __init__(self, name: str, args=None, profile_stats=None): self.name = name self.args = args or {} self.children = [] self.profile_stats = profile_stats def append_child(self, child: 'Operation') -> 'Operation': self.children.append(child) return self def child_count(self) -> int: return len(self.children) @property def execution_time(self) -> int: return self.profile_stats.execution_time if self.profile_stats else 0 @property def records_produced(self) -> int: return self.profile_stats.records_produced if self.profile_stats else 0 class ProfileStats: def __init__(self, records_produced: int, execution_time: float): self.records_produced = records_produced self.execution_time = execution_time class ExecutionPlan: def __init__(self, plan): self.plan = plan # Assume plan is processed to create structured_plan self.structured_plan = None # This would be an Operation object def collect_operations(self, op_name: str) -> list[Operation]: # Placeholder for actual implementation return [] ``` -------------------------------- ### Index Management Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/modules.md Documentation for creating and dropping various types of indexes on nodes and edges. ```APIDOC ## Index Management ### Description Manages indexes for nodes and edges, including fulltext, range, unique, mandatory, and vector indexes. ### Methods for Nodes - **`create_node_fulltext_index(index_name: str, node_labels: list[str], properties: list[str])`** - **`drop_node_fulltext_index(index_name: str)`** - **`create_node_range_index(index_name: str, node_labels: list[str], properties: list[str])`** - **`drop_node_range_index(index_name: str)`** - **`create_node_unique_constraint(index_name: str, node_labels: list[str], properties: list[str])`** - **`drop_node_unique_constraint(index_name: str)`** - **`create_node_mandatory_constraint(index_name: str, node_labels: list[str], properties: list[str])`** - **`drop_node_mandatory_constraint(index_name: str)`** - **`create_node_vector_index(index_name: str, node_labels: list[str], properties: list[str], distance_metric: str = 'cosine')`** - **`drop_node_vector_index(index_name: str)`** ### Methods for Edges - **`create_edge_fulltext_index(index_name: str, edge_labels: list[str], properties: list[str])`** - **`drop_edge_fulltext_index(index_name: str)`** - **`create_edge_range_index(index_name: str, edge_labels: list[str], properties: list[str])`** - **`drop_edge_range_index(index_name: str)`** - **`create_edge_unique_constraint(index_name: str, edge_labels: list[str], properties: list[str])`** - **`drop_edge_unique_constraint(index_name: str)`** - **`create_edge_mandatory_constraint(index_name: str, edge_labels: list[str], properties: list[str])`** - **`drop_edge_mandatory_constraint(index_name: str)`** - **`create_edge_vector_index(index_name: str, edge_labels: list[str], properties: list[str], distance_metric: str = 'cosine')`** - **`drop_edge_vector_index(index_name: str)`** ### Parameters - **`index_name`** (str) - Required - The name of the index. - **`node_labels`** (list[str]) - Required - A list of node labels to apply the index to. - **`edge_labels`** (list[str]) - Required - A list of edge labels to apply the index to. - **`properties`** (list[str]) - Required - A list of property names to index. - **`distance_metric`** (str) - Optional - The distance metric for vector indexes (e.g., 'cosine', 'euclidean', 'dot_product'). Defaults to 'cosine'. ### Usage Example ```python from falkordb import FalkorDB db = FalkorDB.from_url("bolt://neo4j:password@localhost:7687") graph = db.select_graph("my_graph") # Create a node index graph.create_node_range_index(index_name="idx_person_age", node_labels=["Person"], properties=["age"]) # Create an edge index graph.create_edge_unique_constraint(index_name="idx_friendship_since", edge_labels=["FRIENDS_WITH"], properties=["since"]) # Drop an index # graph.drop_node_range_index(index_name="idx_person_age") ``` ### Response #### Success Response: - **message** (str) - Confirmation message that the index operation was successful. ``` -------------------------------- ### Profile Query Execution in FalkorDB Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md Executes a query and produces an execution plan augmented with metrics for each operation's execution. This provides detailed insights into query performance and resource usage. ```python async def profile(query: str, params=None) -> [ExecutionPlan](falkordb.md#falkordb.execution_plan.ExecutionPlan): """Execute a query and produce an execution plan augmented with metrics for each operation’s execution. Return an execution plan, with details on results produced by and time spent in each operation. See: https://docs.falkordb.com/commands/graph.profile.html Args: query (str): The query to profile. params (dict): Query parameters. Returns: ExecutionPlan: The profile information. """ pass ``` -------------------------------- ### Edge Constraint Creation API Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.asyncio.md APIs for creating different types of constraints on edges. ```APIDOC ## POST /falkordb-py/edge/constraint/mandatory ### Description Creates a mandatory constraint for an edge relation. ### Method POST ### Endpoint /falkordb-py/edge/constraint/mandatory ### Parameters #### Path Parameters None #### Query Parameters * **relation** (str) - Required - Edge relationship-type to apply constraint to. * **properties** (list of str) - Required - Variable number of property names to constrain. ### Request Body None ### Request Example ```json { "relation": "REVIEWED", "properties": ["review_text"] } ``` ### Response #### Success Response (200) - **result** (str) - A message indicating the constraint creation status. #### Response Example ```json { "result": "Constraint creation initiated" } ``` --- ## POST /falkordb-py/edge/constraint/unique ### Description Creates a unique constraint for an edge relation. This requires an existing range index over the constraint properties. ### Method POST ### Endpoint /falkordb-py/edge/constraint/unique ### Parameters #### Path Parameters None #### Query Parameters * **relation** (str) - Required - Edge relationship-type to apply constraint to. * **properties** (list of str) - Required - Variable number of property names to constrain. ### Request Body None ### Request Example ```json { "relation": "PURCHASED", "properties": ["transaction_id"] } ``` ### Response #### Success Response (200) - **result** (str) - A message indicating the constraint creation status. #### Response Example ```json { "result": "Constraint creation initiated" } ``` ``` -------------------------------- ### Create Node Full-Text Index Source: https://github.com/falkordb/falkordb-py/blob/main/docs/source/falkordb.md Creates a full-text index for a node label on specified properties. Returns the result of the index creation query. ```python def create_node_fulltext_index(label: str, *properties) -> QueryResult: """Create a full-text index for a node. See: https://docs.falkordb.com/commands/graph.query.html#creating-a-full-text-index-for-a-node-label Args: : label (str): The label of the node. properties: Variable number of property names to be indexed. Returns: : Any: The result of the index creation query. """ pass ```