def test_search_with_filter(node_embeddings: List[TextNode]) -> None:
    """Test end to end construction and search with filter."""
    tidbvec = TiDBVectorStore(
        table_name=VECTOR_TABLE_NAME,
        connection_string=CONNECTION_STRING,
        drop_existing_table=True,
    )

    # Add nodes to the tidb vector
    tidbvec.add(node_embeddings)

    # similarity search
    q = VectorStoreQuery(
        query_embedding=text_to_embedding("foo"),
        similarity_top_k=1,
        filters=MetadataFilters(
            filters=[
                MetadataFilter(key="location", value=100, operator=">"),
            ]
        ),
    )

    result = tidbvec.query(q)
    assert result.nodes is not None and len(result.nodes) == 1
    assert (
        result.nodes[0].get_content(metadata_mode=MetadataMode.NONE)
        == node_embeddings[1].text
    )
    assert (
        result.similarities is not None and result.similarities[0] == 0.9977280385800326
    )
    assert result.ids is not None and result.ids[0] == node_embeddings[1].node_id

    q = VectorStoreQuery(
        query_embedding=text_to_embedding("foo"),
        similarity_top_k=1,
        filters=MetadataFilters(
            filters=[
                MetadataFilter(key="location", value=100, operator=">"),
                MetadataFilter(key="theme", value="Mystery", operator="=="),
            ],
            condition="and",
        ),
    )

    result = tidbvec.query(q)
    assert result.nodes is not None and len(result.nodes) == 0

    q = VectorStoreQuery(
        query_embedding=text_to_embedding("foo"),
        similarity_top_k=1,
        filters=MetadataFilters(
            filters=[
                MetadataFilter(key="location", value=100, operator=">"),
                MetadataFilter(key="theme", value="Mystery", operator="=="),
            ],
            condition="or",
        ),
    )

    result = tidbvec.query(q)
    tidbvec.drop_vectorstore()
    assert result.nodes is not None and len(result.nodes) == 1
    assert (
        result.nodes[0].get_content(metadata_mode=MetadataMode.NONE)
        == node_embeddings[0].text
    )
    assert result.similarities is not None and result.similarities[0] == 1.0
    assert result.ids is not None and result.ids[0] == node_embeddings[0].node_id
Test end to end construction and search with filter.
llama-index-integrations/vector_stores/llama-index-vector-stores-tidbvector/tests/test_vector_stores_tidbvector.py