Skip to content

Commit b7c3426

Browse files
updated example
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
1 parent 1fb7aae commit b7c3426

3 files changed

Lines changed: 15 additions & 34 deletions

File tree

examples/rag/feature_repo/example_repo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
vector_index=True,
3030
vector_search_metric="L2",
3131
),
32+
Field(name="state", dtype=String),
3233
Field(name="sentence_chunks", dtype=String),
3334
Field(name="wiki_summary", dtype=String),
3435
],

examples/rag/feature_repo/feature_store.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ provider: local
33
registry: data/registry.db
44
online_store:
55
type: milvus
6+
path: data/online_store.db
67
vector_enabled: true
78
embedding_dim: 384
9+
index_type: "IVF_FLAT"
810

911

1012
offline_store:

examples/rag/feature_repo/test_workflow.py

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pymilvus import MilvusClient, DataType, FieldSchema
66
from transformers import AutoTokenizer, AutoModel
77
from example_repo import city_embeddings_feature_view, item
8+
89
TOKENIZER = "sentence-transformers/all-MiniLM-L6-v2"
910
MODEL = "sentence-transformers/all-MiniLM-L6-v2"
1011

@@ -42,38 +43,10 @@ def run_demo():
4243
print('\ndata=')
4344
print(df.head().T)
4445

45-
store.apply([city_embeddings_feature_view, item])
46+
# store.apply([city_embeddings_feature_view, item])
4647
store.write_to_online_store("city_embeddings", df)
4748

48-
client = MilvusClient(uir="http://localhost:19530", token="username:password")
49-
fields = [
50-
FieldSchema(name="id", dtype=DataType.INT64, is_primary=True),
51-
FieldSchema(name='state', dtype=DataType.STRING, description="State"),
52-
FieldSchema(name='wiki_summary', dtype=DataType.STRING, description="State"),
53-
FieldSchema(name='sentence_chunks', dtype=DataType.STRING, description="Sentence Chunks"),
54-
FieldSchema(name="item_id", dtype=DataType.INT64, default_value=0, description="Item"),
55-
FieldSchema(name="vector", dtype=DataType.FLOAT_VECTOR, dim=embedding_length, description="vector")
56-
]
57-
cols = [f.name for f in fields]
58-
client.insert(
59-
collection_name="demo_collection",
60-
data=df[cols].to_dict(orient="records"),
61-
schema=fields,
62-
)
63-
print('\n')
64-
print('collections', client.list_collections())
65-
print('query results =', client.query(
66-
collection_name="rag_city_embeddings",
67-
filter="item_id == 0",
68-
# output_fields=['city_embeddings', 'item_id', 'city_name'],
69-
))
70-
print('query results2 =', client.query(
71-
collection_name="rag_city_embeddings",
72-
filter="item_id >= 0",
73-
output_fields=["count(*)"]
74-
# output_fields=['city_embeddings', 'item_id', 'city_name'],
75-
))
76-
question = "the most populous city in the U.S. state of Texas?"
49+
question = "the most populous city in the state of New York is New York"
7750
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER)
7851
model = AutoModel.from_pretrained(MODEL)
7952
query_embedding = run_model(question, tokenizer, model)
@@ -82,12 +55,17 @@ def run_demo():
8255
# Retrieve top k documents
8356
features = store.retrieve_online_documents(
8457
feature=None,
85-
features=["city_embeddings:vector", "city_embeddings:item_id", "city_embeddings:state"],
58+
features=[
59+
"city_embeddings:vector",
60+
"city_embeddings:item_id",
61+
"city_embeddings:state",
62+
],
8663
query=query,
87-
top_k=3
64+
top_k=3,
8865
)
89-
print("features", features.to_df())
90-
66+
print("features =")
67+
print(features.to_df())
68+
# store.teardown()
9169

9270
if __name__ == "__main__":
9371
run_demo()

0 commit comments

Comments
 (0)