Repository: activeloopai/Hub
File: deeplake/core/vectorstore/test_deeplake_vectorstore.py (Python)

Code before:
    with pytest.raises(ValueError):
        vector_store.search(
            query="dummy", filter=filter_fn, exec_option="compute_engine"
        )
    with pytest.raises(ValueError):
        vector_store.search(
            embedding_function=embedding_fn,
        )

    with pytest.raises(ValueError):
        vector_store = DeepLakeVectorStore(path="mem://xyz")

        vector_store.search(
            embedding=query_embedding,
            exec_option="python",
            k=2,
            filter={"metadata": {"abc": 1}},
            return_view=True,
        )

    vector_store = DeepLakeVectorStore(path="mem://xyz")
    vector_store.add(embedding=embeddings, text=texts, metadata=metadatas)

    data = vector_store.search(
        exec_option="python",
        embedding_function=embedding_fn4,
        embedding_data=["dummy"],
        return_view=True,
        k=2,
    )
    assert len(data) == 2
    assert isinstance(data.text[0].data()["value"], str)
    assert data.embedding[0].numpy().size > 0

    data = vector_store.search(
        exec_option="python",
        filter={"metadata": {"abcdefh": 1}},
        embedding=None,
        return_view=True,
        k=2,
    )
    assert len(data) == 0

    data = vector_store.search(
        exec_option="python",
        filter={"metadata": {"abcdefh": 1}},
        embedding=query_embedding,
        k=2,
    )
    assert len(data) == 4
    assert len(data["id"]) == 0

Review comment (suggestion):
but what about the case when the embedding function converts query into list of numpy arrays? in our case our query can be converted into something like: `[np.ndarray(EMBEDDING_DIM)]`, this ideally should also be supported.

Code after:
    with pytest.raises(ValueError):
        vector_store.search(
            query="dummy", filter=filter_fn, exec_option="compute_engine"
        )
    with pytest.raises(ValueError):
        vector_store.search(
            embedding_function=embedding_fn,
        )

    with pytest.raises(ValueError):
        vector_store = DeepLakeVectorStore(path="mem://xyz")

        vector_store.search(
            embedding=query_embedding,
            exec_option="python",
            k=2,
            filter={"metadata": {"abc": 1}},
            return_view=True,
        )

    vector_store = DeepLakeVectorStore(path="mem://xyz")
    vector_store.add(embedding=embeddings, text=texts, metadata=metadatas)

    data = vector_store.search(
        exec_option="python",
        embedding_function=embedding_fn3,
        embedding_data=["dummy"],
        return_view=True,
        k=2,
    )
    assert len(data) == 2
    assert isinstance(data.text[0].data()["value"], str)
    assert data.embedding[0].numpy().size > 0

    data = vector_store.search(
        exec_option="python",
        filter={"metadata": {"abcdefh": 1}},
        embedding=None,
        return_view=True,
        k=2,
    )
    assert len(data) == 0

    data = vector_store.search(
        exec_option="python",
        filter={"metadata": {"abcdefh": 1}},
        embedding=query_embedding,
        k=2,
    )
    assert len(data) == 4
    assert len(data["id"]) == 0