c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
71 lines
2.8 KiB
Python
71 lines
2.8 KiB
Python
from typing import Any
|
|
|
|
from cognee.infrastructure.data.chunking.DefaultChunkEngine import DefaultChunkEngine
|
|
from cognee.infrastructure.data.chunking.HaystackChunkEngine import HaystackChunkEngine
|
|
from cognee.infrastructure.data.chunking.LangchainChunkingEngine import LangchainChunkEngine
|
|
from cognee.shared.data_models import ChunkEngine
|
|
|
|
|
|
class ChunkingConfig(dict):
|
|
"""
|
|
Represent configuration settings for chunking operations, inheriting from the built-in
|
|
Dict class. The class contains the following public attributes:
|
|
|
|
- vector_db_url: A string representing the URL of the vector database.
|
|
- vector_db_key: A string representing the key for accessing the vector database.
|
|
- vector_db_provider: A string representing the provider of the vector database.
|
|
"""
|
|
|
|
vector_db_url: str
|
|
vector_db_key: str
|
|
vector_db_provider: str
|
|
|
|
|
|
def create_chunking_engine(
|
|
config: dict[str, Any],
|
|
) -> LangchainChunkEngine | DefaultChunkEngine | HaystackChunkEngine | None:
|
|
"""
|
|
Create a chunking engine based on the provided configuration.
|
|
|
|
The function selects and returns an instance of a chunking engine class based on the
|
|
`chunk_engine` specified in the `config`. Supported engines are Langchain, Default, and
|
|
Haystack, with their respective configurations for chunk size, overlap, and strategy.
|
|
|
|
Parameters:
|
|
-----------
|
|
|
|
- config (ChunkingConfig): Configuration object containing the settings for the
|
|
chunking engine, including the engine type, chunk size, chunk overlap, and chunk
|
|
strategy.
|
|
|
|
Returns:
|
|
--------
|
|
|
|
An instance of the selected chunking engine class (LangchainChunkEngine,
|
|
DefaultChunkEngine, or HaystackChunkEngine).
|
|
"""
|
|
if config["chunk_engine"] == ChunkEngine.LANGCHAIN_ENGINE:
|
|
from cognee.infrastructure.data.chunking.LangchainChunkingEngine import LangchainChunkEngine
|
|
|
|
return LangchainChunkEngine(
|
|
chunk_size=config["chunk_size"],
|
|
chunk_overlap=config["chunk_overlap"],
|
|
chunk_strategy=config["chunk_strategy"],
|
|
)
|
|
elif config["chunk_engine"] == ChunkEngine.DEFAULT_ENGINE:
|
|
from cognee.infrastructure.data.chunking.DefaultChunkEngine import DefaultChunkEngine
|
|
|
|
return DefaultChunkEngine(
|
|
chunk_size=config["chunk_size"],
|
|
chunk_overlap=config["chunk_overlap"],
|
|
chunk_strategy=config["chunk_strategy"],
|
|
)
|
|
elif config["chunk_engine"] == ChunkEngine.HAYSTACK_ENGINE:
|
|
from cognee.infrastructure.data.chunking.HaystackChunkEngine import HaystackChunkEngine
|
|
|
|
return HaystackChunkEngine(
|
|
chunk_size=config["chunk_size"],
|
|
chunk_overlap=config["chunk_overlap"],
|
|
chunk_strategy=config["chunk_strategy"],
|
|
)
|