client.collections().create(
"documents",
schema={
"title": text().index(semantic_index()).required(),
"content": text().index(semantic_index()).required(),
}
)
client.collection(name).upsert([
{
"_id": "1",
"title": "How to reset router settings to fix intermittent connectivity",
"content": "To fix intermittent connectivity issues related to your device, you need to unplug your modem or router for 10 seconds, then plug them back in. This will cause a reset of the network hardware and often resolves temporary disruptions.",
},
{
"_id": "2",
"title": "How to reset your device",
"content": "Factory reset procedures vary by device. Press and hold the reset button for 10 seconds. This clears all settings, returning the router to default configuration.",
},
])
client.collection(name).query(
select(
"title",
"content",
title_score=fn.bm25_score()
)
.filter(match("how to reset a router", field="title"))
.topk(field("title_score"), 10)
)
# Results:
[
{
"_id": "1",
"title": "How to reset router settings to fix intermittent connectivity",
"title_score": 0.942161500453949,
"content": "To fix intermittent connectivity issues related to your device, you need to unplug your modem or router for 10 seconds, then plug them back in. This will cause a reset of the network hardware and often resolves temporary disruptions.",
},
{
"_id": "2",
"title": "How to reset your device",
"title_score": 0.4156554341316223,
"content": "Factory reset procedures vary by device. Press and hold the reset button for 10 seconds. This clears all settings, returning the router to default configuration.",
}
]