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
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
import asyncio
|
|
from typing import List
|
|
|
|
from cognee.infrastructure.databases.vector.embeddings.LiteLLMEmbeddingEngine import (
|
|
LiteLLMEmbeddingEngine,
|
|
)
|
|
from cognee.shared.rate_limiting import embedding_rate_limiter_context_manager
|
|
|
|
|
|
class MockEmbeddingEngine(LiteLLMEmbeddingEngine):
|
|
"""
|
|
Mock version of LiteLLMEmbeddingEngine that returns fixed embeddings
|
|
and can be configured to simulate rate limiting and failures.
|
|
"""
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.mock = True
|
|
self.fail_every_n_requests = 0
|
|
self.request_count = 0
|
|
self.add_delay = 0
|
|
|
|
def configure_mock(self, fail_every_n_requests=0, add_delay=0):
|
|
"""
|
|
Configure the mock's behavior
|
|
|
|
Args:
|
|
fail_every_n_requests: Raise an exception every n requests (0 = never fail)
|
|
add_delay: Add artificial delay in seconds to each request
|
|
"""
|
|
self.fail_every_n_requests = fail_every_n_requests
|
|
self.add_delay = add_delay
|
|
|
|
async def embed_text(self, text: List[str]) -> List[List[float]]:
|
|
"""
|
|
Mock implementation that returns fixed embeddings and can
|
|
simulate failures and delays based on configuration.
|
|
"""
|
|
self.request_count += 1
|
|
|
|
# Simulate processing delay if configured
|
|
if self.add_delay > 0:
|
|
await asyncio.sleep(self.add_delay)
|
|
|
|
# Simulate failures if configured
|
|
if self.fail_every_n_requests > 0 and self.request_count % self.fail_every_n_requests == 0:
|
|
raise Exception(f"Mock failure on request #{self.request_count}")
|
|
|
|
# Return mock embeddings of the correct dimension
|
|
async with embedding_rate_limiter_context_manager():
|
|
return [[0.1] * self.dimensions for _ in text]
|