"""Own learning example. Artificial vectors; not an embedding or quality test. Only run against a separate local test instance. Requires qdrant-client. Creates a NEW collection and refuses to replace/delete an existing one. """ import math COLLECTION = "tokenwerk_lernprobe_20261020" ROWS = [ {"id": 101, "vector": [1.0, 0.0, 0.0], "payload": {"quelle": "TW-A", "bereich": "public"}}, {"id": 102, "vector": [0.0, 1.0, 0.0], "payload": {"quelle": "TW-B", "bereich": "public"}}, {"id": 103, "vector": [0.8, 0.2, 0.0], "payload": {"quelle": "TW-C", "bereich": "intern"}}, ] def validate(rows): ids = set() for row in rows: if type(row["id"]) is not int or row["id"] in ids: raise ValueError("Each point needs a different integer ID") ids.add(row["id"]) v = row["vector"] if len(v) != 3 or any(type(x) not in (int, float) or not math.isfinite(x) for x in v): raise ValueError("Expected exactly three finite numbers") if row["payload"]["bereich"] not in {"public", "intern"}: raise ValueError("Unknown toy filter value") return rows def run(client=None): from qdrant_client import QdrantClient, models rows = validate(ROWS) if client is None: client = QdrantClient(url="http://127.0.0.1:6333", timeout=10) client.create_collection( collection_name=COLLECTION, vectors_config=models.VectorParams(size=3, distance=models.Distance.DOT), ) client.upsert( collection_name=COLLECTION, wait=True, points=[models.PointStruct(**row) for row in rows], ) query = [1.0, 0.0, 0.0] all_points = client.query_points( collection_name=COLLECTION, query=query, with_payload=True, limit=3, ).points public_points = client.query_points( collection_name=COLLECTION, query=query, query_filter=models.Filter(must=[models.FieldCondition( key="bereich", match=models.MatchValue(value="public"), )]), with_payload=True, limit=3, ).points for title, points in [("All toy points", all_points), ("Toy payload filter", public_points)]: print(title) for point in points: print(point.id, point.score, point.payload) return all_points, public_points if __name__ == "__main__": run()