### Install an Official Kuzu Extension Source: https://docs.kuzudb.com/extensions Installs an official Kuzu extension. This command only needs to be run once per extension. Extensions are downloaded from the default Kuzu extension server. ```sql INSTALL "extension_name"; ``` -------------------------------- ### Start Kuzu CLI Source: https://docs.kuzudb.com/client-apis/cli Starts the Kuzu Command Line Interface (CLI) for interacting with databases. It supports both on-disk and in-memory database modes. ```bash kuzu ``` ```bash kuzu ``` -------------------------------- ### CMake Integration for KuzuDB C Library Source: https://docs.kuzudb.com/client-apis/c Example CMake configuration for integrating the pre-built KuzuDB C library into a project. This snippet shows how to use FetchContent to download and build Kuzu as a dependency and link it to an example executable, supporting both static and dynamic linking. ```CMake cmake_minimum_required(VERSION 3.20) project(kuzu_example) set(EXAMPLE_SHARED OFF CACHE BOOL "Build example as shared library") include(FetchContent) FetchContent_Declare( kuzu GIT_REPOSITORY https://github.com/kuzudb/kuzu.git GIT_TAG v0.3.0 # Or any other tag ) FetchContent_MakeAvailable(kuzu) add_executable(kuzu_example main.c) if(${EXAMPLE_SHARED}) target_link_libraries(kuzu_example PRIVATE kuzu::kuzu_shared) else() target_link_libraries(kuzu_example PRIVATE kuzu::kuzu_static) endif() ``` -------------------------------- ### Kuzu Extension Installation Source: https://docs.kuzudb.com/developer-guide/files Command to install official Kuzu extensions, downloading libraries to the user's home directory. ```SQL INSTALL ``` -------------------------------- ### Install Kuzu Extension from Custom Server Source: https://docs.kuzudb.com/extensions Installs a Kuzu extension from a custom-hosted extension server. This is useful for air-gapped environments. The FROM clause specifies the URL of the custom server. ```sql INSTALL "extension_name" FROM "http://your-server-address:port/"; ``` -------------------------------- ### Install Kuzu Rust Client Source: https://docs.kuzudb.com/installation Installs the Kuzu Rust client library using Cargo. This method builds Kuzu's C++ library from source by default, allowing static linking. ```Shell cargo install kuzu ``` -------------------------------- ### Install Kuzu Nightly Python Source: https://docs.kuzudb.com/installation Installs the pre-release version of the Kuzu Python client using uv pip. This provides access to the latest features in development. ```Shell uv pip install --pre kuzu ``` -------------------------------- ### Install Kuzu Nightly Node.js Source: https://docs.kuzudb.com/installation Installs the next version of the Kuzu Node.js client using npm. This provides access to the latest features in development. ```Shell npm i kuzu@next ``` -------------------------------- ### Install Kuzu C/C++ Binaries Source: https://docs.kuzudb.com/installation Downloads the latest version of the Kuzu C/C++ binaries using curl. These binaries include the necessary library files and header for C/C++ integration. ```Shell curl -fsSL https://kuzu.dev/install | bash ``` -------------------------------- ### Install Kuzu Node.js Client Source: https://docs.kuzudb.com/installation Installs the Kuzu Node.js client library using npm. This allows developers to integrate Kuzu into their Node.js applications. ```Shell npm install kuzu ``` -------------------------------- ### Install and Load Kuzu 'algo' Extension Source: https://docs.kuzudb.com/get-started/graph-algorithms Installs and loads the 'algo' extension within Kuzu to enable native graph algorithm execution. ```Cypher INSTALL 'algo'; LOAD 'algo'; ``` -------------------------------- ### Install Node.js Dependencies for Kuzu Source: https://docs.kuzudb.com/developer-guide Installs the required dependencies for building Kuzu's Node.js bindings using npm. ```Shell npm install ``` -------------------------------- ### Swift: Initialize Project and Add Dependency Source: https://docs.kuzudb.com/get-started Guides on initializing a new Swift project using the Swift Package Manager and adding the 'kuzu-swift' client as a dependency. ```bash swift package init --type executable # Update Package.swift with the kuzu-swift dependency ``` ```swift import PackageDescription let package = Package( name: "kuzu-example", platforms: [ .macOS(.v10_15) ], products: [ .executable(name: "kuzu-example", targets: ["kuzu-example"]) ], dependencies: [ .package(url: "https://github.com/kuzudb/kuzu-swift", from: "0.4.0") ], targets: [ .executableTarget(name: "kuzu-example", dependencies: ["kuzu"]) ] ) ``` -------------------------------- ### Install Kuzu Python Client Source: https://docs.kuzudb.com/installation Installs the Kuzu Python client library using package managers like uv, pip, or nix. This library enables embedding Kuzu within Python applications. ```Shell uv pip install kuzu ``` ```Shell pip install kuzu ``` ```Shell nix-shell -p python3Packages.kuzu ``` -------------------------------- ### Create Example Graph in Neo4j Source: https://docs.kuzudb.com/extensions/neo4j These Cypher queries create an example graph with User and City nodes, and LivesIn and Follows relationships in Neo4j, serving as a dataset for demonstrating the Neo4j migration extension. ```cypher CREATE (user1:User {name: 'Alice'}), (user2:User {name: 'Bob'}), (user3:User {name: 'Charlie'}); CREATE (city1:City {name: 'New York'}), (city2:City {name: 'London'}); CREATE (user1)-[:LivesIn {since: 2020}]->(city1); CREATE (user2)-[:LivesIn {since: 2018}]->(city2); CREATE (user3)-[:LivesIn {since: 2022}]->(city1); CREATE (user1)-[:Follows {since: 2021}]->(user2); CREATE (user2)-[:Follows {since: 2022}]->(user3); ``` -------------------------------- ### Install Kuzu CLI via curl Source: https://docs.kuzudb.com/installation Installs the latest version of the Kuzu Command Line Interface (CLI) using curl. This is a standalone executable with no dependencies for interacting with Kuzu databases via Cypher. ```Shell curl -fsSL https://kuzu.dev/install | bash ``` -------------------------------- ### Install Python Dependencies for Kuzu Source: https://docs.kuzudb.com/developer-guide Installs the necessary dependencies for building Kuzu's Python bindings. This command assumes a package manager is available. ```Shell pip install -r requirements.txt ``` -------------------------------- ### List Available Kuzu Extensions Source: https://docs.kuzudb.com/extensions Lists all official Kuzu extensions that are available for installation. This command helps users discover available functionalities. ```sql LIST "extensions"; ``` -------------------------------- ### Kuzu Extension Loading Source: https://docs.kuzudb.com/developer-guide/files Command to load an installed Kuzu extension, searching for it in the extensions directory. ```SQL LOAD ``` -------------------------------- ### Filter Users by Age or Name Prefix Source: https://docs.kuzudb.com/cypher/query-clauses/where This example demonstrates filtering User nodes based on their age being greater than 45 or their name starting with 'Kar'. It utilizes boolean operators, numeric comparisons, and string functions within the WHERE clause. ```KuzuDB MATCH (u:User) WHERE u.age > 45 OR starts_with(u.name, "Kar") RETURN u; ``` -------------------------------- ### Install Kuzu CLI via Homebrew Source: https://docs.kuzudb.com/installation Installs the Kuzu Command Line Interface (CLI) using the Homebrew package manager. This method allows for easy installation and management of the Kuzu CLI on macOS and Linux systems. ```Shell brew install kuzu ``` -------------------------------- ### Rust: Kuzu Crate Initialization Source: https://docs.kuzudb.com/get-started Shows how to initialize a new Rust project and add the 'kuzu' crate as a dependency for using KuzuDB. ```bash cargo new kuzu_example cd kuzu_example # Add kuzu to Cargo.toml # [dependencies] # kuzu = "0.4.0" ``` -------------------------------- ### Add Kuzu Swift Package Source: https://docs.kuzudb.com/installation Adds the kuzu-swift package to a Swift project using the Swift Package Manager. This enables the use of Kuzu within Swift applications. ```Swift dependencies: [ .package(url: "https://github.com/kuzudb/kuzu-swift", from: "0.11.2") ] ``` -------------------------------- ### Java: Minimal build.gradle Configuration Source: https://docs.kuzudb.com/get-started Presents a minimal build.gradle file configuration for a Java application using the Kuzu client library. ```gradle plugins { id 'java' id 'application' } repositories { mavenCentral() } dependencies { implementation 'ai.kuzu:kuzu-java:0.4.0' } application { mainClass = 'Main' } ``` -------------------------------- ### Swift: Copy Executable for Data Access Source: https://docs.kuzudb.com/get-started Instructions on copying the compiled Swift executable to a location where it can access the 'data' directory, specifying architecture for Intel Macs or Linux. ```bash # For Intel Mac or Linux: cp .build/arm64-apple-macosx/debug/kuzu-example /usr/local/bin/ # For Apple Silicon Mac: # cp .build/aarch64-apple-macosx/debug/kuzu-example /usr/local/bin/ ``` -------------------------------- ### Find Followers of Top Users (WITH) Source: https://docs.kuzudb.com/tutorials/cypher Shows how to chain query results using the WITH clause. This example finds the top 3 users with the most posts and then identifies their followers. ```Cypher MATCH (u:User)-[:POSTED]->(p:Post) WITH u, count(p) AS postCount ORDER BY postCount DESC LIMIT 3 MATCH (follower:User)-[:FOLLOWS]->(u) RETURN follower.name, u.name AS followedUser, postCount ``` -------------------------------- ### Kuzu CLI: Create and Query Database Source: https://docs.kuzudb.com/get-started Demonstrates how to create an on-disk Kuzu database using the CLI and execute Cypher statements, emphasizing the need for semicolons to terminate queries. ```bash # Create a database named 'my_db' kuzu ./my_db # Enter Cypher statements, each terminated by a semicolon CREATE (u:User {ID: 1, name: 'Alice'})-[:LIVES_IN]->(c:City {ID: 1, name: 'New York'}); CREATE (u:User {ID: 2, name: 'Bob'})-[:LIVES_IN]->(c:City {ID: 2, name: 'San Francisco'}); MATCH (u:User)-[r:LIVES_IN]->(c:City) RETURN u.name, c.name; # Exit the shell exit; ``` -------------------------------- ### C: Compile and Run Main Application (Windows) Source: https://docs.kuzudb.com/get-started Instructions for compiling and running a C application using the Kuzu client library on Windows, noting how the library is passed to the compiler. ```bash gcc main.c -I./include -L./lib -lkuzu -o main.exe # Runtime search path is handled automatically if kuzu_shared.dll is in the current directory ``` -------------------------------- ### Kuzu Python API Tutorial Source: https://docs.kuzudb.com/tutorials This tutorial introduces Kuzu's Python API, guiding users through its features and usage within the Python data science ecosystem. ```Python import kuzu db = kuzu.Database() conn = kuzu.Connection(db) # Example query conn.execute("CREATE NODE TABLE Person(name STRING, age INT);") conn.execute("CREATE (p:Person {name: 'Alice', age: 30})") result = conn.execute("MATCH (p:Person) RETURN p.name, p.age;") print(result.get_data()) ``` -------------------------------- ### KuzuDB INTERVAL Example Source: https://docs.kuzudb.com/cypher/data-types Shows an example of the INTERVAL data type in KuzuDB, representing date/time differences. ```SQL CREATE TABLE t(i INTERVAL); INSERT INTO t VALUES ('3 days'); ``` -------------------------------- ### C: Compile and Run Main Application (Linux) Source: https://docs.kuzudb.com/get-started Instructions for compiling and running a C application using the Kuzu client library on Linux, including linker path adjustments. ```bash gcc main.c -I./include -L./lib -lkuzu -o main export LD_LIBRARY_PATH=./lib:$LD_LIBRARY_PATH ./main ``` -------------------------------- ### KuzuDB STRING Example Source: https://docs.kuzudb.com/cypher/data-types Shows an example of using the STRING data type in KuzuDB, which supports UTF-8 encoding. ```SQL CREATE TABLE t(s STRING); INSERT INTO t VALUES ('hello world'); ``` -------------------------------- ### Kuzu CLI Help Source: https://docs.kuzudb.com/client-apis/cli Displays a list of all available commands and their usage within the Kuzu CLI shell. ```bash kuzu -h ``` -------------------------------- ### KuzuDB UUID Example Source: https://docs.kuzudb.com/cypher/data-types Provides an example of how the UUID data type is used in KuzuDB to store Universally Unique Identifiers. ```SQL CREATE TABLE t(uuid UUID); INSERT INTO t VALUES ('a4e3e3e3-12e3-4e3e-3e3e-3e3e3e3e3e3e'); ``` -------------------------------- ### Kuzu Rust API Tutorial Source: https://docs.kuzudb.com/tutorials This tutorial provides an introduction to Kuzu's Rust API, enabling developers to interact with Kuzu using Rust. ```Rust use kuzu::Kuzu; fn main() { let mut database = Kuzu::new("path/to/your/database").unwrap(); let mut transaction = database.transaction().unwrap(); // Example query transaction.execute("CREATE NODE TABLE Movie(title STRING, release_year INT);").unwrap(); transaction.execute("CREATE (m:Movie {title: 'Inception', release_year: 2010})").unwrap(); let result = transaction.execute("MATCH (m:Movie) RETURN m.title, m.release_year;").unwrap(); for row in result.iter() { println!("{:?}", row); } } ``` -------------------------------- ### C: Compile and Run Main Application (macOS) Source: https://docs.kuzudb.com/get-started Instructions for compiling and running a C application using the Kuzu client library on macOS, including linker path adjustments. ```bash gcc main.c -I./include -L./lib -lkuzu -o main export DYLD_LIBRARY_PATH=./lib:$DYLD_LIBRARY_PATH ./main ``` -------------------------------- ### Generate Range List in KuzuDB Source: https://docs.kuzudb.com/cypher/expressions/list-functions Creates a list of sequential values starting from `start` up to (but not including) `stop`. Steps can be specified. ```KuzuDB range(start, stop) ``` -------------------------------- ### Create Kuzu Graph and Load Data Source: https://docs.kuzudb.com/get-started/graph-algorithms Initializes a Kuzu database, creates 'Scholar' node and 'MENTORED' relationship tables, and ingests data using MERGE commands. ```Cypher CREATE DATABASE example.kuzu; CREATE TABLE Scholar(name STRING, age INT, country STRING); CREATE ORDERED RELSHIP TABLE MENTORED(FROM Scholar TO Scholar, register_year INT); MERGE FROM CSV "/path/to/scholar.csv" INTO "Scholar" (name, age, country); MERGE FROM CSV "/path/to/mentored.csv" INTO "MENTORED" (from_scholar, to_scholar, register_year); ``` -------------------------------- ### KuzuDB TIMESTAMP Example Source: https://docs.kuzudb.com/cypher/data-types Provides an example of the TIMESTAMP data type in KuzuDB, showing its ISO-8601 format for date and time combinations with timezone offsets. ```SQL CREATE TABLE t(ts TIMESTAMP); INSERT INTO t VALUES ('2023-01-01 10:00:00.000+00'); ``` -------------------------------- ### C++: Organize Kuzu Library Files Source: https://docs.kuzudb.com/get-started Example of organizing Kuzu C++ client library files (header and shared library) and application source code in a directory structure. ```shell kuzu_project/ ├── include/ │ └── kuzu.hpp ├── lib/ │ └── libkuzu.so # or .dylib, .dll └── main.cpp ``` -------------------------------- ### Run Kuzu Extension Server with Docker Source: https://docs.kuzudb.com/extensions Starts a Kuzu extension server using Docker. This allows hosting extensions locally, which is useful for air-gapped environments or private extension management. ```bash docker run -d -p 8080:80 \ --name kuzu-extension-server \ kuzudb/extension-server:latest ``` -------------------------------- ### Launch Kuzu Explorer with an empty database (Docker) Source: https://docs.kuzudb.com/visualization/kuzu-explorer Launches Kuzu Explorer using a Docker image with an empty database. This is achieved by omitting the volume mount for an existing database. The server starts with a default or newly created 'database.kz' file. ```Shell docker run -d -p 8000:8000 --rm ghcr.io/kuzudb/kuzu-explorer:main ``` -------------------------------- ### Kuzu Cypher Tutorial Source: https://docs.kuzudb.com/tutorials This tutorial covers the basics of Cypher, the query language used by Kuzu, helping users understand its syntax and capabilities. ```Cypher MATCH (p:Person {name: 'Alice'}) RETURN p.age ``` -------------------------------- ### Filtered Vector Search Example (Python) Source: https://docs.kuzudb.com/extensions/vector Demonstrates how to perform a filtered vector search in KuzuDB using Python. This example searches for books similar to a query, filtered by their publication year. ```Python from kuzu import GraphDB db = GraphDB() # Assume 'books' table has 'title', 'embedding', and 'publication_year' columns # Assume a vector index is built on the 'embedding' column query = "quantum world" publication_year_threshold = 2010 # Construct the Cypher query with filtering cypher_query = f''' MATCH (b:Book) WHERE b.publication_year > {publication_year_threshold} CALL db.similarity.cosine(b.embedding, "{query}") YIELD score RETURN b.title, score ORDER BY score DESC LIMIT 2 ''' result = db.execute(cypher_query) print(result.get_data()) ``` -------------------------------- ### C++: Compile and Run Main Application Source: https://docs.kuzudb.com/get-started Command to compile and run a C++ application that uses the Kuzu client library, specifying include and library paths. ```bash g++ main.cpp -I./include -L./lib -lkuzu -o main ./main ``` -------------------------------- ### Rust: Main Application Code Source: https://docs.kuzudb.com/get-started Contains the Rust code for creating a Kuzu database, defining a schema, and inserting data. ```rust use kuzu::prelude::*; fn main() { // Create a database in the given directory let mut database = Database::new("../data").unwrap(); let mut connection = Connection::new(&mut database).unwrap(); // Create nodes and relationships connection.execute("CREATE (u:User {ID: 1, name: 'Alice'})-[:LIVES_IN]->(c:City {ID: 1, name: 'New York'})").unwrap(); connection.execute("CREATE (u:User {ID: 2, name: 'Bob'})-[:LIVES_IN]->(c:City {ID: 2, name: 'San Francisco'})").unwrap(); // Query the database let mut result = connection.execute("MATCH (u:User)-[r:LIVES_IN]->(c:City) RETURN u.name, c.name").unwrap(); while let Some(row) = result.next() { let values = row.unwrap(); println!("{} lives in {}", values[0].to_string(), values[1].to_string()); } } ``` -------------------------------- ### Install yFiles Jupyter Graphs Widget Source: https://docs.kuzudb.com/visualization/third-party-integrations/yfiles Installs the yFiles Jupyter Graphs widget for Kuzu using either uv or pip package managers. This is the first step to enable graph visualization in Jupyter notebooks. ```Shell uv install yfiles-jupyter-graphs ``` ```Shell pip install yfiles-jupyter-graphs ``` -------------------------------- ### C: Main Application Code Source: https://docs.kuzudb.com/get-started Contains the C code for creating a Kuzu database, defining a schema, and inserting data. ```c #include #include "include/kuzu.h" int main() { // Create a database in the given directory kuzu_database_t* database = kuzu_database_init("../data", KUZU_DEFAULT_CONFIG); kuzu_connection_t* connection = kuzu_connection_init(database); // Create nodes and relationships kuzu_connection_query(connection, "CREATE (u:User {ID: 1, name: 'Alice'})-[:LIVES_IN]->(c:City {ID: 1, name: 'New York'})"); kuzu_connection_query(connection, "CREATE (u:User {ID: 2, name: 'Bob'})-[:LIVES_IN]->(c:City {ID: 2, name: 'San Francisco'})"); // Query the database kuzu_query_result_t* result = kuzu_connection_query(connection, "MATCH (u:User)-[r:LIVES_IN]->(c:City) RETURN u.name, c.name"); while (kuzu_query_result_has_next(result)) { kuzu_row_t* row = kuzu_query_result_get_next(result); kuzu_value_t** values = kuzu_row_get_values(row); printf("%s lives in %s\n", kuzu_value_to_string(values[0]), kuzu_value_to_string(values[1])); kuzu_free_row(row); } kuzu_query_result_destroy(result); kuzu_connection_destroy(connection); kuzu_database_destroy(database); return 0; } ``` -------------------------------- ### Browser In-Memory Kuzu Wasm Example Source: https://docs.kuzudb.com/client-apis/wasm Demonstrates using Kuzu WebAssembly in a browser with an in-memory filesystem. This example showcases basic graph creation and querying within the browser environment without persistent storage. ```javascript import * as kuzu from 'kuzu-wasm'; async function runExample() { // Initialize Kuzu in memory const db = await kuzu.KuzuDatabase.create('./'); const conn = await db.createConnection(); // Create a schema and insert data await conn.execute( 'CREATE (:Person {name: "Alice"}), (:Person {name: "Bob"}) CREATE (:Person {name: "Charlie"}) CREATE (p1:Person {name: "Alice"})-[:KNOWS]->(p2:Person {name: "Bob"})' ); // Execute a query const result = await conn.execute('MATCH (n:Person) RETURN n.name'); console.log(result.toArray()); await db.close(); } runExample(); ``` -------------------------------- ### Swift: Main Application Code Source: https://docs.kuzudb.com/get-started Provides the Swift code for creating a Kuzu database, defining a schema, and inserting data. ```swift import Kuzu func main() { // Create a database in the given directory let database = try! Database(directory: "../data") let connection = try! Connection(database: database) // Create nodes and relationships try! connection.execute(query: "CREATE (u:User {ID: 1, name: 'Alice'})-[:LIVES_IN]->(c:City {ID: 1, name: 'New York'})") try! connection.execute(query: "CREATE (u:User {ID: 2, name: 'Bob'})-[:LIVES_IN]->(c:City {ID: 2, name: 'San Francisco'})") // Query the database let result = try! connection.execute(query: "MATCH (u:User)-[r:LIVES_IN]->(c:City) RETURN u.name, c.name") while let row = try? result.next() { if let values = row { print("\(values[0]) lives in \(values[1])") } } } main() ``` -------------------------------- ### LangChain-Kuzu Integration Source: https://docs.kuzudb.com/tutorials Demonstrates using Kuzu as a property graph store for LangChain, enabling seamless integration of Kuzu's graph capabilities into LangChain workflows. ```Python from langchain_community.graphs import KuzuGraph # Initialize KuzuGraph # kuzu_graph = KuzuGraph(db_path="path/to/kuzu_db") # Example: Query the graph using LangChain # query = "MATCH (p:Person) RETURN p.name LIMIT 5" # result = kuzu_graph.query(query) # print(result) ``` -------------------------------- ### Get Current Date in KuzuDB Source: https://docs.kuzudb.com/cypher/expressions/date-functions Returns the current system date. ```SQL SELECT current_date(); ``` -------------------------------- ### Kuzu and NetworkX Integration Source: https://docs.kuzudb.com/tutorials Demonstrates how to use Kuzu with NetworkX for graph algorithms, showing how to work with graph data in both libraries. ```Python import kuzu import networkx as nx db = kuzu.Database() conn = kuzu.Connection(db) conn.execute("CREATE NODE TABLE Node(id INT);") conn.execute("CREATE EDGE TABLE Edge(src INT, dst INT);") # Create a NetworkX graph G = nx.DiGraph() G.add_edge(1, 2) # Load NetworkX graph into Kuzu conn.from_networkx(G) # Query Kuzu graph result = conn.execute("MATCH (n) RETURN count(n);") print(result.get_data()) ``` -------------------------------- ### Get Map Size in KuzuDB Source: https://docs.kuzudb.com/cypher/expressions/map-functions Returns the number of key-value pairs in a map. ```KuzuDB cardinality(map([1, 2], ['a', 'b'])) ``` -------------------------------- ### Get Month Name in KuzuDB Source: https://docs.kuzudb.com/cypher/expressions/date-functions Returns the English name of the month for a given date. ```SQL SELECT monthname(DATE('2022-11-07')); -- Result: "November" (STRING) ``` -------------------------------- ### KuzuDB String Size Source: https://docs.kuzudb.com/cypher/expressions/text-functions Shows the `size` function to get the total number of characters in a string. ```KuzuDB size("database") ``` -------------------------------- ### Get Map Values in KuzuDB Source: https://docs.kuzudb.com/cypher/expressions/map-functions Returns a list containing all the values present in a map. ```KuzuDB map_values(map([1, 2], ['a', 'b'])) ``` -------------------------------- ### Create Sample DuckDB Database (Python) Source: https://docs.kuzudb.com/extensions/attach/duckdb Creates a sample DuckDB database named 'university.db' with a 'students' table containing student information. This serves as an example for attaching to Kuzu. ```Python import duckdb con = duckdb.connect(database='university.db', read_only=False) con.execute("CREATE TABLE students (id INTEGER, name VARCHAR, age INTEGER)") con.execute("INSERT INTO students VALUES (1, 'Alice', 20), (2, 'Bob', 22)") con.close() ``` -------------------------------- ### Get Map Keys in KuzuDB Source: https://docs.kuzudb.com/cypher/expressions/map-functions Returns a list containing all the keys present in a map. ```KuzuDB map_keys(map([1, 2], ['a', 'b'])) ``` -------------------------------- ### Launch Kuzu Explorer with an existing database (Docker) Source: https://docs.kuzudb.com/visualization/kuzu-explorer Launches Kuzu Explorer using a Docker image, mounting an existing Kuzu database file to the container. This allows modifications made in the UI to persist to the local database file. The `--rm` flag ensures the container is removed upon closure. ```Shell docker run -d -p 8000:8000 --rm -v {path to the directory containing the database file}:/database -e KUZU_FILE={database file name} ghcr.io/kuzudb/kuzu-explorer:main ``` -------------------------------- ### Initialize On-Disk Database (C++) Source: https://docs.kuzudb.com/get-started Initializes a KuzuDB database in on-disk mode using C++, persisting data to the specified file path. This mode utilizes a Write-Ahead Log (WAL) for transaction management and periodic checkpoints. ```C++ #include kuzu::Database db("example.kuzu"); ``` -------------------------------- ### Get Last Day of Month in KuzuDB Source: https://docs.kuzudb.com/cypher/expressions/date-functions Returns the last day of the month for a given date. ```SQL SELECT last_day(DATE('2022-10-11')); -- Result: 2022-10-31 (DATE) ``` -------------------------------- ### LlamaIndex-Kuzu Integration Source: https://docs.kuzudb.com/tutorials Shows how to use Kuzu as a property graph store for LlamaIndex, facilitating efficient data retrieval and querying within LlamaIndex applications. ```Python from llama_index.graph_stores import KuzuGraphStore from llama_index.indices.graph.base import KnowledgeGraphIndex # Initialize KuzuGraphStore # graph_store = KuzuGraphStore(db_path="path/to/kuzu_db") # Build a KnowledgeGraphIndex using KuzuGraphStore # index = KnowledgeGraphIndex.from_documents(documents, graph_store=graph_store) # Query the index # query_engine = index.as_query_engine() # response = query_engine.query("What are the main topics?") ``` -------------------------------- ### Get Day Name in KuzuDB Source: https://docs.kuzudb.com/cypher/expressions/date-functions Returns the English name of the day of the week for a given date. ```SQL SELECT dayname(DATE('2022-11-07')); -- Result: "Monday" (STRING) ``` -------------------------------- ### KuzuDB Sum Function Source: https://docs.kuzudb.com/cypher/expressions/aggregate-functions Calculates the sum of values for all tuples in the argument. Usage example: sum(a.length). ```KuzuDB sum(arg) ``` -------------------------------- ### Initialize On-Disk Database (Python) Source: https://docs.kuzudb.com/get-started Initializes a KuzuDB database in on-disk mode, persisting data to the specified file path. This mode uses a Write-Ahead Log (WAL) for transaction logging and checkpoints. ```Python from kuzu import Database db = Database("example.kuzu") ``` -------------------------------- ### KuzuDB Maximum Function Source: https://docs.kuzudb.com/cypher/expressions/aggregate-functions Returns the maximum value of the given argument. Usage example: max(a.length). ```KuzuDB max(arg) ``` -------------------------------- ### KuzuDB Minimum Function Source: https://docs.kuzudb.com/cypher/expressions/aggregate-functions Returns the minimum value of the given argument. Usage example: min(a.length). ```KuzuDB min(arg) ``` -------------------------------- ### Create Read-Write Database and Connection in Python Source: https://docs.kuzudb.com/concurrency Demonstrates the two-step process to create a read-write Kuzu database instance and establish a connection for executing queries. This example uses Python and assumes a database file named 'example.kuzu'. ```Python from kuzu import * db = Database("example.kuzu", READ_WRITE) conn = Connection(db) ``` -------------------------------- ### KuzuDB Count Function Source: https://docs.kuzudb.com/cypher/expressions/aggregate-functions Returns the number of tuples in the specified argument. Usage example: count(a.ID). ```KuzuDB count(arg) ``` -------------------------------- ### Get Current Timestamp - SQL Source: https://docs.kuzudb.com/cypher/expressions/timestamp-functions Returns the current timestamp at the time of execution. This function does not require any arguments. ```SQL SELECT current_timestamp() ``` -------------------------------- ### Python: Integrate Kuzu Query Results with PyArrow Table Source: https://docs.kuzudb.com/get-started Demonstrates using the PyArrow library to work with Kuzu query results as Arrow Tables in Python, facilitating interoperability with systems using Arrow. ```python import pyarrow as pa from kuzu import Connection # Assume 'conn' is an established Kuzu Connection object # Assume 'query' is a Cypher query string # Execute query and get results as a PyArrow Table arrow_table = conn.execute(query).get_as_arrow() print(arrow_table.schema) ``` -------------------------------- ### Get Node/Relationship Offset Source: https://docs.kuzudb.com/cypher/expressions/node-rel-functions The OFFSET function returns the offset of the internal ID for a node or relationship. ```KuzuDB MATCH (n) RETURN OFFSET(ID(n)) ``` -------------------------------- ### Get First Non-NULL Value in KuzuDB Source: https://docs.kuzudb.com/cypher/expressions/list-functions Returns the first non-NULL value encountered in a list. ```KuzuDB list_any_value(list) ``` -------------------------------- ### KuzuDB Collect Function Source: https://docs.kuzudb.com/cypher/expressions/aggregate-functions Returns a list of values generated by the argument expression. Usage example: collect(a.age). ```KuzuDB collect(arg) ``` -------------------------------- ### Create Database Connection - KuzuDB Source: https://docs.kuzudb.com/developer-guide/testing-framework Initiates a connection to the database. Connection names must follow the 'conn.*' prefix, allowing for multiple named connections. ```KuzuDB -CREATE_CONNECTION conn.* ``` -------------------------------- ### Launch Kuzu Explorer with custom buffer pool size (Docker) Source: https://docs.kuzudb.com/visualization/kuzu-explorer Launches Kuzu Explorer with a specified buffer pool size in bytes by setting the KUZU_BUFFER_POOL_SIZE environment variable. This example sets the buffer pool size to 1GB. ```Shell docker run -d -p 8000:8000 --rm -v {path to the directory containing the database file}:/database -e KUZU_FILE={database file name} -e KUZU_BUFFER_POOL_SIZE=1073741824 ghcr.io/kuzudb/kuzu-explorer:main ``` -------------------------------- ### KuzuDB Average Function Source: https://docs.kuzudb.com/cypher/expressions/aggregate-functions Calculates the average value of all tuples in a given argument. Usage example: avg(a.length). ```KuzuDB avg(arg) ``` -------------------------------- ### Create Node and Relationship Tables - SQL Source: https://docs.kuzudb.com/extensions/algo/louvain This snippet demonstrates the SQL syntax for creating the necessary node and relationship tables required before running graph algorithms in KuzuDB. ```SQL CREATE TABLE nodes (id INT64, name STRING); CREATE TABLE relationships (from INT64, to INT64, type STRING); ``` -------------------------------- ### Work with LIST and ARRAY in SQL Source: https://docs.kuzudb.com/cypher/data-types Example usage of LIST (variable-length) and ARRAY (fixed-length) data types in KuzuDB. ```SQL CREATE TABLE T(list_col LIST(INT64), array_col ARRAY(STRING, 5)); ``` -------------------------------- ### Rust: Create Kuzu Database and Import Data Source: https://docs.kuzudb.com/tutorials/rust Creates a new Kuzu database file named 'social_network.kuzu' and imports data from specified CSV files into node and relationship tables. This function initializes the graph database. ```rust use kuzu::Kuzu; fn main() { let db = Kuzu::new("social_network.kuzu").unwrap(); db.execute("CREATE NODE TABLE Users(user_id INT64, username STRING, PRIMARY KEY(user_id))") .unwrap(); db.execute("CREATE NODE TABLE Posts(post_id INT64, content STRING, PRIMARY KEY(post_id))") .unwrap(); db.execute("CREATE REL TABLE Follows(FROM Users TO Users, PRIMARY KEY(FROM, TO))") .unwrap(); db.execute("LOAD FROM "users.csv" INTO Users") .unwrap(); db.execute("LOAD FROM "posts.csv" INTO Posts") .unwrap(); db.execute("LOAD FROM "follows.csv" INTO Follows") .unwrap(); let result = db.execute("MATCH (n) RETURN n").unwrap(); println!("{}", result.to_string()); } ``` -------------------------------- ### KuzuDB DATE Example Source: https://docs.kuzudb.com/cypher/data-types Demonstrates the usage of the DATE data type in KuzuDB, specifying dates in ISO-8601 format. ```SQL CREATE TABLE t(d DATE); INSERT INTO t VALUES ('2023-01-01'); ```