Skip to content

Commit 7879f65

Browse files
committed
fix linter 2
1 parent 224d0a1 commit 7879f65

File tree

2 files changed

+46
-30
lines changed

2 files changed

+46
-30
lines changed

sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ def retrieve_online_documents_v2(
495495
]:
496496
"""
497497
Retrieve documents using vector similarity search or keyword search in Milvus.
498-
499498
Args:
500499
config: Feast configuration object
501500
table: FeatureView object as the table to search
@@ -504,7 +503,6 @@ def retrieve_online_documents_v2(
504503
top_k: Number of items to return
505504
distance_metric: Distance metric to use (optional)
506505
query_string: The query string to search for using keyword search (optional)
507-
508506
Returns:
509507
List of tuples containing the event timestamp, entity key, and feature values
510508
"""
@@ -539,22 +537,30 @@ def retrieve_online_documents_v2(
539537
if embedding is not None:
540538
for field in collection["fields"]:
541539
if (
542-
field["type"] in [DataType.FLOAT_VECTOR, DataType.BINARY_VECTOR]
543-
and field["name"] in output_fields
540+
field["type"] in [DataType.FLOAT_VECTOR, DataType.BINARY_VECTOR]
541+
and field["name"] in output_fields
544542
):
545543
ann_search_field = field["name"]
546544
break
547545

548546
self.client.load_collection(collection_name)
549547

550-
if embedding is not None and query_string is not None and config.online_store.vector_enabled:
548+
if (
549+
embedding is not None
550+
and query_string is not None
551+
and config.online_store.vector_enabled
552+
):
551553
string_field_list = [
552-
f.name for f in table.features if
553-
isinstance(f.dtype, PrimitiveFeastType) and f.dtype.to_value_type() == ValueType.STRING
554+
f.name
555+
for f in table.features
556+
if isinstance(f.dtype, PrimitiveFeastType)
557+
and f.dtype.to_value_type() == ValueType.STRING
554558
]
555559

556560
if not string_field_list:
557-
raise ValueError("No string fields found in the feature view for text search in hybrid mode")
561+
raise ValueError(
562+
"No string fields found in the feature view for text search in hybrid mode"
563+
)
558564

559565
# Create a filter expression for text search
560566
filter_expressions = []
@@ -600,12 +606,16 @@ def retrieve_online_documents_v2(
600606

601607
elif query_string is not None:
602608
string_field_list = [
603-
f.name for f in table.features if
604-
isinstance(f.dtype, PrimitiveFeastType) and f.dtype.to_value_type() == ValueType.STRING
609+
f.name
610+
for f in table.features
611+
if isinstance(f.dtype, PrimitiveFeastType)
612+
and f.dtype.to_value_type() == ValueType.STRING
605613
]
606614

607615
if not string_field_list:
608-
raise ValueError("No string fields found in the feature view for text search")
616+
raise ValueError(
617+
"No string fields found in the feature view for text search"
618+
)
609619

610620
filter_expressions = []
611621
for field in string_field_list:
@@ -615,7 +625,9 @@ def retrieve_online_documents_v2(
615625
filter_expr = " OR ".join(filter_expressions)
616626

617627
if not filter_expr:
618-
raise ValueError("No text fields found in requested features for search")
628+
raise ValueError(
629+
"No text fields found in requested features for search"
630+
)
619631

620632
query_results = self.client.query(
621633
collection_name=collection_name,
@@ -624,7 +636,9 @@ def retrieve_online_documents_v2(
624636
limit=top_k,
625637
)
626638

627-
results = [[{"entity": entity, "distance": -1.0}] for entity in query_results]
639+
results = [
640+
[{"entity": entity, "distance": -1.0}] for entity in query_results
641+
]
628642
else:
629643
raise ValueError(
630644
"Either vector_enabled must be True for embedding search or query_string must be provided for keyword search"

sdk/python/tests/unit/online_store/test_online_retrieval.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,16 +1502,16 @@ def test_milvus_keyword_search() -> None:
15021502
teardown=False,
15031503
) as store:
15041504
from datetime import timedelta
1505-
1505+
15061506
from feast import Entity, FeatureView, Field, FileSource
15071507
from feast.types import Array, Float32, Int64, String, UnixTimestamp
1508-
1508+
15091509
rag_documents_source = FileSource(
15101510
path="data/embedded_documents.parquet",
15111511
timestamp_field="event_timestamp",
15121512
created_timestamp_column="created_timestamp",
15131513
)
1514-
1514+
15151515
item = Entity(
15161516
name="item_id",
15171517
join_keys=["item_id"],
@@ -1522,7 +1522,7 @@ def test_milvus_keyword_search() -> None:
15221522
join_keys=["author_id"],
15231523
value_type=ValueType.STRING,
15241524
)
1525-
1525+
15261526
document_embeddings = FeatureView(
15271527
name="text_documents",
15281528
entities=[item, author],
@@ -1543,13 +1543,13 @@ def test_milvus_keyword_search() -> None:
15431543
source=rag_documents_source,
15441544
ttl=timedelta(hours=24),
15451545
)
1546-
1546+
15471547
store.apply([rag_documents_source, item, document_embeddings])
1548-
1548+
15491549
# Write some data with specific text content for keyword search
15501550
document_embeddings_fv = store.get_feature_view(name="text_documents")
15511551
provider = store._get_provider()
1552-
1552+
15531553
contents = [
15541554
"Feast is an open source feature store for machine learning",
15551555
"Feature stores solve the problem of coordinating features for training and serving",
@@ -1562,7 +1562,7 @@ def test_milvus_keyword_search() -> None:
15621562
"Offline stores are used for batch feature retrieval during training",
15631563
"Feast enables data scientists to define, manage, and share features",
15641564
]
1565-
1565+
15661566
titles = [
15671567
"Introduction to Feast",
15681568
"Feature Store Benefits",
@@ -1575,7 +1575,7 @@ def test_milvus_keyword_search() -> None:
15751575
"Offline Training Support",
15761576
"Feast for Data Scientists",
15771577
]
1578-
1578+
15791579
item_keys = [
15801580
EntityKeyProto(
15811581
join_keys=["item_id", "author_id"],
@@ -1604,14 +1604,14 @@ def test_milvus_keyword_search() -> None:
16041604
_utc_now(),
16051605
)
16061606
)
1607-
1607+
16081608
provider.online_write_batch(
16091609
config=store.config,
16101610
table=document_embeddings_fv,
16111611
data=data,
16121612
progress=None,
16131613
)
1614-
1614+
16151615
# Test keyword search for "Milvus"
16161616
result_milvus = store.retrieve_online_documents_v2(
16171617
features=[
@@ -1621,11 +1621,11 @@ def test_milvus_keyword_search() -> None:
16211621
query_string="Milvus",
16221622
top_k=3,
16231623
).to_dict()
1624-
1624+
16251625
# Verify that documents containing "Milvus" are returned
16261626
assert len(result_milvus["content"]) > 0
16271627
assert any("Milvus" in content for content in result_milvus["content"])
1628-
1628+
16291629
# Test keyword search for "machine learning"
16301630
result_ml = store.retrieve_online_documents_v2(
16311631
features=[
@@ -1635,11 +1635,13 @@ def test_milvus_keyword_search() -> None:
16351635
query_string="machine learning",
16361636
top_k=3,
16371637
).to_dict()
1638-
1638+
16391639
# Verify that documents containing "machine learning" are returned
16401640
assert len(result_ml["content"]) > 0
1641-
assert any("machine learning" in content.lower() for content in result_ml["content"])
1642-
1641+
assert any(
1642+
"machine learning" in content.lower() for content in result_ml["content"]
1643+
)
1644+
16431645
# Test hybrid search (vector + keyword)
16441646
query_embedding = np.random.random(vector_length).tolist()
16451647
result_hybrid = store.retrieve_online_documents_v2(
@@ -1652,7 +1654,7 @@ def test_milvus_keyword_search() -> None:
16521654
query_string="Feast",
16531655
top_k=3,
16541656
).to_dict()
1655-
1657+
16561658
# Verify hybrid search results
16571659
assert len(result_hybrid["content"]) > 0
16581660
assert any("Feast" in content for content in result_hybrid["content"])

0 commit comments

Comments
 (0)