You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import subprocess
  2. import time
  3. from core.rag.datasource.vdb.couchbase.couchbase_vector import CouchbaseConfig, CouchbaseVector
  4. from tests.integration_tests.vdb.test_vector_store import (
  5. AbstractVectorTest,
  6. setup_mock_redis,
  7. )
  8. def wait_for_healthy_container(service_name="couchbase-server", timeout=300):
  9. start_time = time.time()
  10. while time.time() - start_time < timeout:
  11. result = subprocess.run(
  12. ["docker", "inspect", "--format", "{{.State.Health.Status}}", service_name], capture_output=True, text=True
  13. )
  14. if result.stdout.strip() == "healthy":
  15. print(f"{service_name} is healthy!")
  16. return True
  17. else:
  18. print(f"Waiting for {service_name} to be healthy...")
  19. time.sleep(10)
  20. raise TimeoutError(f"{service_name} did not become healthy in time")
  21. class CouchbaseTest(AbstractVectorTest):
  22. def __init__(self):
  23. super().__init__()
  24. self.vector = CouchbaseVector(
  25. collection_name=self.collection_name,
  26. config=CouchbaseConfig(
  27. connection_string="couchbase://127.0.0.1",
  28. user="Administrator",
  29. password="password",
  30. bucket_name="Embeddings",
  31. scope_name="_default",
  32. ),
  33. )
  34. def search_by_vector(self):
  35. # brief sleep to ensure document is indexed
  36. time.sleep(5)
  37. hits_by_vector = self.vector.search_by_vector(query_vector=self.example_embedding)
  38. assert len(hits_by_vector) == 1
  39. def test_couchbase(setup_mock_redis):
  40. wait_for_healthy_container("couchbase-server", timeout=60)
  41. CouchbaseTest().run_all_tests()