Skip to main content

Falkor hybrid database adapter for cognee

Project description

Cognee Community FalkorDB Hybrid Adapter

This is a community-maintained adapter that enables Cognee to work with FalkorDB as a hybrid graph database.

Installation

pip install cognee-community-hybrid-adapter-falkor

Usage

import asyncio
import os
import pathlib
from os import path
from cognee import config, prune, add, cognify, search, SearchType

# Import the register module to enable FalkorDB support
from cognee_community_hybrid_adapter_falkor import register

async def main():
    # Set up local directories
    system_path = pathlib.Path(__file__).parent
    config.system_root_directory(path.join(system_path, ".cognee_system"))
    config.data_root_directory(path.join(system_path, ".cognee_data"))
    
    # Configure databases
    config.set_relational_db_config({
        "db_provider": "sqlite",
    })
    
    # Configure FalkorDB as both vector and graph database
    config.set_vector_db_config({
        "vector_db_provider": "falkor",
        "vector_db_url": os.getenv("GRAPH_DB_URL", "localhost"),
        "vector_db_port": int(os.getenv("GRAPH_DB_PORT", "6379")),
    })
    config.set_graph_db_config({
        "graph_database_provider": "falkor",
        "graph_database_url": os.getenv("GRAPH_DB_URL", "localhost"),
        "graph_database_port": int(os.getenv("GRAPH_DB_PORT", "6379")),
    })
    
    # Optional: Clean previous data
    await prune.prune_data()
    await prune.prune_system(metadata=True)
    
    # Add and process your content
    await add("""
    Natural language processing (NLP) is an interdisciplinary
    subfield of computer science and information retrieval.
    """)
    
    await add("""
    Sandwiches are best served toasted with cheese, ham, mayo,
    lettuce, mustard, and salt & pepper.          
    """)
    
    await cognify()
    
    # Search using graph completion
    query_text = "Tell me about NLP"
    search_results = await search(
        query_type=SearchType.GRAPH_COMPLETION,
        query_text=query_text
    )
    
    for result in search_results:
        print("\nSearch result: \n" + result)

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

Configuration

The FalkorDB adapter can be configured as both a vector database and graph database, providing true hybrid capabilities. The following configuration parameters are available:

Graph Database Configuration:

  • graph_database_provider: Set to "falkordb"
  • graph_database_url: Your FalkorDB server hostname (default: "localhost")
  • graph_database_port: Your FalkorDB server port (default: 6379)

Vector Database Configuration (optional - enables hybrid mode):

  • vector_db_provider: Set to "falkordb"
  • vector_db_url: Your FalkorDB server hostname (default: "localhost")
  • vector_db_port: Your FalkorDB server port (default: 6379)

Environment Variables

Set the following environment variables or pass them directly in the config, or set the in the .env file:

export GRAPH_DB_URL="localhost"
export GRAPH_DB_PORT="6379"
export GRAPH_DATASET_DATABASE_HANDLER="falkor_graph_local"
export VECTOR_DATASET_DATABASE_HANDLER="falkor_vector_local"

Alternative: You can also use the .env.template file from the main cognee repository. Copy it to your project directory, rename it to .env, and fill in your FalkorDB configuration values.

Requirements

  • Python >= 3.11, <= 3.13
  • falkordb >= 1.0.9, < 2.0.0
  • cognee >= 0.2.0.dev0

Features

  • True Hybrid Database: Use FalkorDB as both vector and graph database in a single instance
  • Full graph database capabilities with Cypher query support
  • Vector similarity search and indexing
  • Redis-based protocol support for high performance
  • Hybrid storage and retrieval operations
  • Async/await support
  • Graph queries and traversals
  • Knowledge graph construction and semantic analysis
  • Unified data management across vector and graph domains

About FalkorDB

FalkorDB is a graph database that combines the power of Redis with graph capabilities. It provides:

  • High-performance graph operations
  • Redis-compatible protocol
  • Cypher query language support
  • Real-time graph analytics
  • Scalable graph storage

This adapter allows Cognee to leverage FalkorDB's hybrid capabilities for advanced knowledge graph operations and semantic search.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cognee_community_hybrid_adapter_falkor-0.3.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file cognee_community_hybrid_adapter_falkor-0.3.0.tar.gz.

File metadata

File hashes

Hashes for cognee_community_hybrid_adapter_falkor-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7684e204fc3b032a7582fd3d91f55bcf66c99e45257ec2a72151827dcc9d52da
MD5 e77f65c20b9ab613c0e6a447fa6b1c01
BLAKE2b-256 8db5100d6f3761e4a21f9ccf3801e620195bc51a12a3bd7f105b87afff22a04e

See more details on using hashes here.

File details

Details for the file cognee_community_hybrid_adapter_falkor-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cognee_community_hybrid_adapter_falkor-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50d91954d3549f6c82b025e886234c62754dfd4692c6f372cee084e60f52d422
MD5 74cbd7fb72ffc588ecb4d8307f7c43b5
BLAKE2b-256 aa7944e49d606d8a40b3c08d92e045c59bd7c393dabc18af1ab72a30a6233303

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page