test_lindorm.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import environs
  2. from core.rag.datasource.vdb.lindorm.lindorm_vector import LindormVectorStore, LindormVectorStoreConfig
  3. from tests.integration_tests.vdb.test_vector_store import AbstractVectorTest, setup_mock_redis
  4. env = environs.Env()
  5. class Config:
  6. SEARCH_ENDPOINT = env.str("SEARCH_ENDPOINT", "http://ld-************-proxy-search-pub.lindorm.aliyuncs.com:30070")
  7. SEARCH_USERNAME = env.str("SEARCH_USERNAME", "ADMIN")
  8. SEARCH_PWD = env.str("SEARCH_PWD", "ADMIN")
  9. USING_UGC = env.bool("USING_UGC", True)
  10. class TestLindormVectorStore(AbstractVectorTest):
  11. def __init__(self):
  12. super().__init__()
  13. self.vector = LindormVectorStore(
  14. collection_name=self.collection_name,
  15. config=LindormVectorStoreConfig(
  16. hosts=Config.SEARCH_ENDPOINT,
  17. username=Config.SEARCH_USERNAME,
  18. password=Config.SEARCH_PWD,
  19. ),
  20. )
  21. def get_ids_by_metadata_field(self):
  22. ids = self.vector.get_ids_by_metadata_field(key="doc_id", value=self.example_doc_id)
  23. assert ids is not None
  24. assert len(ids) == 1
  25. assert ids[0] == self.example_doc_id
  26. class TestLindormVectorStoreUGC(AbstractVectorTest):
  27. def __init__(self):
  28. super().__init__()
  29. self.vector = LindormVectorStore(
  30. collection_name="ugc_index_test",
  31. config=LindormVectorStoreConfig(
  32. hosts=Config.SEARCH_ENDPOINT,
  33. username=Config.SEARCH_USERNAME,
  34. password=Config.SEARCH_PWD,
  35. using_ugc=Config.USING_UGC,
  36. ),
  37. routing_value=self.collection_name,
  38. )
  39. def get_ids_by_metadata_field(self):
  40. ids = self.vector.get_ids_by_metadata_field(key="doc_id", value=self.example_doc_id)
  41. assert ids is not None
  42. assert len(ids) == 1
  43. assert ids[0] == self.example_doc_id
  44. def test_lindorm_vector_ugc(setup_mock_redis):
  45. TestLindormVectorStore().run_all_tests()
  46. TestLindormVectorStoreUGC().run_all_tests()