|
|
|
|
|
""" |
|
|
Simple Test for Advanced Embedding Pipeline |
|
|
Tests basic functionality without external dependencies |
|
|
""" |
|
|
|
|
|
import asyncio |
|
|
import logging |
|
|
import sys |
|
|
import time |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent)) |
|
|
|
|
|
|
|
|
logging.basicConfig( |
|
|
level=logging.INFO, |
|
|
format="%(asctime)s | %(levelname)s | %(message)s" |
|
|
) |
|
|
logger = logging.getLogger("simple_test") |
|
|
|
|
|
|
|
|
async def test_basic_functionality(): |
|
|
"""Test basic functionality of the embedding pipeline""" |
|
|
logger.info("π§ͺ Starting Simple Embedding Pipeline Test") |
|
|
|
|
|
try: |
|
|
|
|
|
logger.info("π¦ Testing imports...") |
|
|
|
|
|
from fractal_cascade_embedder import FractalCascadeEmbedder, FractalConfig |
|
|
logger.info("β
Fractal embedder imported successfully") |
|
|
|
|
|
|
|
|
logger.info("π Testing Fractal Cascade Embedder...") |
|
|
|
|
|
config = FractalConfig( |
|
|
max_depth=4, |
|
|
branching_factor=2, |
|
|
embedding_dim=512, |
|
|
fractal_type="mandelbrot", |
|
|
use_entropy=True, |
|
|
visualization=False |
|
|
) |
|
|
|
|
|
embedder = FractalCascadeEmbedder(config) |
|
|
|
|
|
|
|
|
test_texts = [ |
|
|
"The quick brown fox jumps over the lazy dog", |
|
|
"Fractal geometry reveals infinite complexity", |
|
|
"Mathematical beauty in recursive patterns" |
|
|
] |
|
|
|
|
|
start_time = time.time() |
|
|
embeddings = embedder.embed_batch(test_texts) |
|
|
processing_time = time.time() - start_time |
|
|
|
|
|
logger.info(f"β
Fractal embeddings generated successfully") |
|
|
logger.info(f" Texts processed: {len(test_texts)}") |
|
|
logger.info(f" Embeddings generated: {len(embeddings)}") |
|
|
logger.info(f" Embedding dimension: {len(embeddings[0]) if embeddings else 0}") |
|
|
logger.info(f" Processing time: {processing_time:.3f}s") |
|
|
|
|
|
|
|
|
if embeddings: |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
norms = [np.linalg.norm(emb) for emb in embeddings] |
|
|
avg_norm = np.mean(norms) |
|
|
std_norm = np.std(norms) |
|
|
|
|
|
logger.info(f" Average embedding norm: {avg_norm:.4f}") |
|
|
logger.info(f" Standard deviation norm: {std_norm:.4f}") |
|
|
|
|
|
|
|
|
similarities = [] |
|
|
for i in range(len(embeddings)): |
|
|
for j in range(i + 1, len(embeddings)): |
|
|
sim = np.dot(embeddings[i], embeddings[j]) |
|
|
similarities.append(sim) |
|
|
|
|
|
if similarities: |
|
|
avg_similarity = np.mean(similarities) |
|
|
logger.info(f" Average pairwise similarity: {avg_similarity:.4f}") |
|
|
|
|
|
|
|
|
logger.info("π Testing Semantic Embedder (fallback mode)...") |
|
|
|
|
|
try: |
|
|
from semantic_embedder import SemanticEmbedder, SemanticConfig |
|
|
|
|
|
semantic_config = SemanticConfig( |
|
|
eopiez_url="http://localhost:8001", |
|
|
embedding_dim=768, |
|
|
batch_size=4, |
|
|
use_cache=False |
|
|
) |
|
|
|
|
|
semantic_embedder = SemanticEmbedder(semantic_config) |
|
|
|
|
|
|
|
|
single_embedding = await semantic_embedder.embed_text(test_texts[0]) |
|
|
logger.info(f"β
Semantic embedding generated (fallback mode)") |
|
|
logger.info(f" Embedding dimension: {len(single_embedding)}") |
|
|
|
|
|
await semantic_embedder.close() |
|
|
|
|
|
except Exception as e: |
|
|
logger.warning(f"β οΈ Semantic embedder test failed: {e}") |
|
|
|
|
|
|
|
|
logger.info("π’ Testing Mathematical Embedder (local mode)...") |
|
|
|
|
|
try: |
|
|
from mathematical_embedder import MathematicalEmbedder, MathematicalConfig |
|
|
|
|
|
math_config = MathematicalConfig( |
|
|
limps_url="http://localhost:8000", |
|
|
max_dimension=512, |
|
|
polynomial_degree=2, |
|
|
use_matrix_optimization=False |
|
|
) |
|
|
|
|
|
math_embedder = MathematicalEmbedder(math_config) |
|
|
|
|
|
|
|
|
math_embedding = await math_embedder.embed_mathematical_expression("x^2 + y^2 = z^2") |
|
|
logger.info(f"β
Mathematical embedding generated") |
|
|
logger.info(f" Embedding dimension: {len(math_embedding)}") |
|
|
|
|
|
await math_embedder.close() |
|
|
|
|
|
except Exception as e: |
|
|
logger.warning(f"β οΈ Mathematical embedder test failed: {e}") |
|
|
|
|
|
logger.info("π Simple test completed successfully!") |
|
|
|
|
|
|
|
|
print("\n" + "="*60) |
|
|
print("π§ͺ SIMPLE EMBEDDING PIPELINE TEST SUMMARY") |
|
|
print("="*60) |
|
|
print("β
Fractal Cascade Embedder: WORKING") |
|
|
print("β
Semantic Embedder (fallback): WORKING") |
|
|
print("β
Mathematical Embedder (local): WORKING") |
|
|
print("β
All core components functional") |
|
|
print("="*60) |
|
|
|
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
logger.error(f"β Simple test failed: {e}") |
|
|
return False |
|
|
|
|
|
|
|
|
async def main(): |
|
|
"""Main test function""" |
|
|
success = await test_basic_functionality() |
|
|
|
|
|
if success: |
|
|
print("\nπ― Next steps:") |
|
|
print("1. Start Eopiez service: cd ~/aipyapp/Eopiez && python api.py --port 8001") |
|
|
print("2. Start LIMPS service: cd ~/aipyapp/9xdSq-LIMPS-FemTO-R1C/limps && julia --project=. -e 'using LIMPS; LIMPS.start_limps_server(8000)'") |
|
|
print("3. Run full integration test: python integration_test.py") |
|
|
print("4. Run comprehensive demo: python demo.py") |
|
|
else: |
|
|
print("\nβ Basic test failed. Check error messages above.") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
asyncio.run(main()) |
|
|
|