Feat: add a support for OpenSearch and AstraDB components to yield the langchain vector_store connection object (#6998)

* Added decorator, decorator test, and modified supported vector stores

* Renamed module file name to reflect that this is for generic use, not use for graph rag

* Updated docsstring

* Improved documentation and modification to UT to support graph rag

* Remove extra file from PR

* rollback vector store template

* [autofix.ci] apply automated fixes

---------

Co-authored-by: Nadir J <31660040+NadirJ@users.noreply.github.com>
Co-authored-by: cristhianzl <cristhian.lousa@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Pedro Pacheco 2025-03-11 18:41:34 -06:00 • committed by GitHub
commit eedef1efae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 127 additions and 2 deletions

View file

@ -0,0 +1,36 @@
from typing import Any
import pytest
from langflow.components.vectorstores import AstraDBVectorStoreComponent
from tests.base import ComponentTestBaseWithoutClient, VersionComponentMapping
class TestVectorStoreDecorator(ComponentTestBaseWithoutClient):
"""Unit tests for the AstraDBVectorStoreComponent decorator.
This test class inherits from ComponentTestBaseWithoutClient and includes
the following tests and fixtures:
Fixtures:
- component_class: Returns the AstraDBVectorStoreComponent class to be tested.
- file_names_mapping: Returns an empty list representing the file names mapping for different versions.
Tests:
- test_decorator_applied: Verifies that the AstraDBVectorStoreComponent has the 'decorated' attribute and that
it is set to True.
"""
@pytest.fixture
def component_class(self) -> type[Any]:
"""Return the component class to test."""
return AstraDBVectorStoreComponent
@pytest.fixture
def file_names_mapping(self) -> list[VersionComponentMapping]:
"""Return the file names mapping for different versions."""
return []
def test_decorator_applied(self, component_class: type[Any]):
component: AstraDBVectorStoreComponent = component_class()
assert hasattr(component, "decorated")
assert component.decorated

View file

@ -30,7 +30,13 @@ def ingestion_graph():
openai_embeddings.set(
openai_api_key="sk-123", openai_api_base="https://api.openai.com/v1", openai_api_type="openai"
)
vector_store = AstraDBVectorStoreComponent(_id="ingestion-vector-store-123")
# Mock search_documents by changing the value otherwise set by the vector_store_connection_decorator
vector_store.set_on_output(name="vectorstoreconnection", value=[Data(text="This is a test file.")], cache=True)
vector_store.set_on_output(name="vectorstoreconnection", value=[Data(text="This is a test file.")], cache=True)
vector_store.set_on_output(name="search_results", value=[Data(text="This is a test file.")], cache=True)
vector_store.set_on_output(name="dataframe", value=DataFrame(data=[Data(text="This is a test file.")]), cache=True)
vector_store.set(