topoteretes--cognee
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 行
1.7 KiB
Python
52 行
1.7 KiB
Python
from typing import List, Union
|
|
from cognee.shared.logging_utils import setup_logging
|
|
|
|
logger = setup_logging()
|
|
|
|
|
|
def is_embeddable(s: str) -> bool:
|
|
"""
|
|
Check if input string is embeddable, if not it will be replaced with a dummy value to prevent API errors.
|
|
Empty strings and a string with only a space character are not embeddable.
|
|
If input string contains at least one alphanumeric character, it is considered embeddable.
|
|
"""
|
|
if not isinstance(s, str):
|
|
return False
|
|
# Strip whitespace to check if the string is empty or only contains spaces
|
|
s = s.strip()
|
|
if len(s) >= 1:
|
|
return True
|
|
logger.debug(
|
|
"Input string was not embeddable. Skipping embedding and using dummy value instead."
|
|
)
|
|
return False
|
|
|
|
|
|
def sanitize_embedding_text_inputs(text: Union[str, List[str]]) -> List[str]:
|
|
"""
|
|
Transform invalid/empty inputs into a safe dummy to prevent API 422 embedding errors while
|
|
keeping list length consistent.
|
|
"""
|
|
# Ensure we are working with a list
|
|
text_list = [text] if isinstance(text, str) else text
|
|
dummy_value = "."
|
|
|
|
return [t if is_embeddable(t) else dummy_value for t in text_list]
|
|
|
|
|
|
def handle_embedding_response(
|
|
original_texts: Union[List[str], str], embeddings: List[List[float]], dimensions: int
|
|
) -> List[List[float]]:
|
|
"""
|
|
Compare the original input strings against the results.
|
|
If the original string was 'junk' that was not embeddable, overwrite its vector with zeros.
|
|
"""
|
|
if isinstance(original_texts, str):
|
|
original_texts = [original_texts]
|
|
|
|
zero_vector = [0.0] * dimensions
|
|
return [
|
|
embeddings[i] if is_embeddable(original_texts[i]) else zero_vector
|
|
for i in range(len(original_texts))
|
|
]
|