DATN_Query_Routing / search.py
qminh369's picture
Upload 7 files
eaf119d verified
raw
history blame contribute delete
585 Bytes
from utils import load_model, load_collection
search_params = search_params = {
"metric_type": "COSINE", # L2
"params": {"level": 2}
}
def search_chunks(query, model_name, collection_name, topk=5):
model = load_model(model_name)
collection = load_collection(collection_name)
embed_query = model.encode(query)
results = collection.search(
[embed_query],
anns_field="chunk_embedding",
param=search_params,
limit=topk,
guarantee_timestamp=1,
output_fields=['chunk_ref', 'chunk_text'] #
)
return results[0]