Skip to main content

Weaviate vector database adapter for cognee

Project description

Cognee Community Weaviate Vector Adapter

This is a community-maintained adapter that enables Cognee to work with Weaviate as a vector database.

Installation

If published, the package can be simply installed via pip:

pip install cognee-community-vector-adapter-weaviate

In case it is not published yet, you can use poetry to locally build the adapter package:

pip install poetry
poetry install # run this command in the directory containing the pyproject.toml file

Connection Setup

The provided code creates an async client connected to a remote instance of Weaviate. If you want to connect to a local instance, like running a docker container locally and connecting to it, you need to change a few lines of code. In the weaviate_adapter.py file inside the .../weaviate/cognee_community_vector_adapter_weaviate directory, replace the following lines in the constructor:

self.client = weaviate.use_async_with_weaviate_cloud(
    cluster_url=url,
    auth_credentials=weaviate.auth.AuthApiKey(api_key),
    additional_config=wvc.init.AdditionalConfig(timeout=wvc.init.Timeout(init=30)),
)

with the following:

self.client = weaviate.use_async_with_local(
    host="localhost",
    port=8080,
    grpc_port=50051
)

You can use the docker command provided by Weaviate (https://docs.weaviate.io/deploy/installation-guides/docker-installation) to run Weaviate with default settings. The command looks something like this, specifying the ports for connection: docker run -p 8080:8080 -p 50051:50051 cr.weaviate.io/semitechnologies/weaviate:1.32.4

Usage

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

# Import the register module to enable Weaviate support
import cognee_community_vector_adapter_weaviate.register

async def main():
    # Configure databases
    config.set_relational_db_config({
        "db_provider": "sqlite",
    })
    config.set_vector_db_config({
        "vector_db_provider": "weaviate",
        "vector_db_url": os.getenv("VECTOR_DB_URL"),  # or your Weaviate URL
        "vector_db_key": os.getenv("VECTOR_DB_KEY"),  # or your API key
    })
    config.set_graph_db_config({
        "graph_database_provider": "networkx",
    })
    
    # Optional: Clean previous data
    await prune.prune_data()
    await prune.prune_system()
    
    # Add and process your content
    text = "Your text content here"
    await add(text)
    await cognify()
    
    # Search
    search_results = await search(
        query_type=SearchType.GRAPH_COMPLETION,
        query_text="Your search query"
    )
    
    for result in search_results:
        print(result)

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

Configuration

The Weaviate adapter requires the following configuration parameters:

  • vector_db_url: Your Weaviate cluster endpoint URL
  • vector_db_key: Your Weaviate API key
  • vector_db_provider: Set to "weaviate"

Environment Variables

Set the following environment variables or pass them directly in the config:

export VECTOR_DB_URL="https://your-weaviate-instance.weaviate.network"
export VECTOR_DB_KEY="your-api-key"

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 Weaviate configuration values.

Requirements

  • Python >= 3.11, <= 3.13
  • weaviate-client >= 4.9.6, < 5.0.0
  • cognee >= 0.2.1

Features

  • Full vector search capabilities
  • Batch operations support
  • Async/await support
  • Retry logic for better reliability
  • Collection management
  • Data point indexing and retrieval

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

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_vector_adapter_weaviate-0.0.2.tar.gz.

File metadata

File hashes

Hashes for cognee_community_vector_adapter_weaviate-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8df7680690efb4cf352da97f8c9f60fe418931a21e0eab5cd04531c86bc70805
MD5 d1ac8152ade7d8db4cc1f1a96f1598b3
BLAKE2b-256 d05161f9583fcea7c011ccf8408e2fc6cd2961739a33178d53bb93e4b5d16da0

See more details on using hashes here.

File details

Details for the file cognee_community_vector_adapter_weaviate-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cognee_community_vector_adapter_weaviate-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 90b6b89575014b05fb7467958e8dc9ee1a44614c0101ce411030d5fb0c9f5b5d
MD5 dd195a2685f11e6c1faa61f06e5bf4b6
BLAKE2b-256 e41f85856cb5fcc42205ee6de9e3d765d97ad6a5b09c31d6338658603f9ff8b2

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