55from pymilvus import MilvusClient , DataType , FieldSchema
66from transformers import AutoTokenizer , AutoModel
77from example_repo import city_embeddings_feature_view , item
8+
89TOKENIZER = "sentence-transformers/all-MiniLM-L6-v2"
910MODEL = "sentence-transformers/all-MiniLM-L6-v2"
1011
@@ -42,38 +43,10 @@ def run_demo():
4243 print ('\n data=' )
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
9270if __name__ == "__main__" :
9371 run_demo ()
0 commit comments