Compare commits
3 Commits
7b76c8cfef
...
a0efd90c14
| Author | SHA1 | Date | |
|---|---|---|---|
| a0efd90c14 | |||
| 6dda8ac74c | |||
| a217eb05f2 |
101
src/app.py
101
src/app.py
@ -32,6 +32,66 @@ def health_healthz():
|
|||||||
return jsonify("OK"), 200
|
return jsonify("OK"), 200
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/add_points")
|
||||||
|
def add_points():
|
||||||
|
#doc uuid and clauses: [{},{}]
|
||||||
|
if request.content_type == 'application/json':
|
||||||
|
try:
|
||||||
|
data = request.get_json(force=True)
|
||||||
|
if data is None:
|
||||||
|
raise BadRequest
|
||||||
|
except BadRequest:
|
||||||
|
return jsonify({"error": "Invalid JSON"}), 400
|
||||||
|
else:
|
||||||
|
|
||||||
|
data = request.form.to_dict()
|
||||||
|
|
||||||
|
doc_uuid=data.get("doc_uuid")
|
||||||
|
clauses = data.get("clauses", [])
|
||||||
|
if not doc_uuid or not clauses:
|
||||||
|
return jsonify({"error": "Missing 'doc_uuid' or 'clauses' in request"}), 400
|
||||||
|
|
||||||
|
vector_points = []
|
||||||
|
|
||||||
|
for clause in clauses:
|
||||||
|
clause_id = clause.get("clause_id")
|
||||||
|
line_item = clause.get("line_item")
|
||||||
|
line_number = clause.get("line_number")
|
||||||
|
|
||||||
|
if not clause_id or not line_item:
|
||||||
|
return jsonify({"error":"Missing fileds in clause"}), 400
|
||||||
|
|
||||||
|
try:
|
||||||
|
clause_vectors=Embedding.call(line_item)
|
||||||
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": f"Embedding failed: {str(e)}"}), 500
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"doc_id": doc_uuid,
|
||||||
|
"clause_id": clause_id,
|
||||||
|
"line_item": line_item,
|
||||||
|
"line_number": line_number
|
||||||
|
}
|
||||||
|
|
||||||
|
for vector in clause_vectors:
|
||||||
|
point = PointStruct(
|
||||||
|
id=str(uuid.uuid7()),
|
||||||
|
vector=vector.tolist(),
|
||||||
|
payload=payload
|
||||||
|
)
|
||||||
|
vector_points.append(point)
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = Qdrant.get_client().upsert(
|
||||||
|
points= vector_points
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": f"Qdrant upsert failed: {str(e)}"}), 500
|
||||||
|
|
||||||
|
return jsonify({"message": f"{len(vector_points)} points added successfully"}), 200
|
||||||
|
|
||||||
@app.post("/add")
|
@app.post("/add")
|
||||||
def add():
|
def add():
|
||||||
if request.content_type == 'application/json':
|
if request.content_type == 'application/json':
|
||||||
@ -80,6 +140,47 @@ def add():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/delete_points")
|
||||||
|
def delete_points():
|
||||||
|
if request.content_type == 'application/json':
|
||||||
|
try:
|
||||||
|
data = request.get_json(force=True)
|
||||||
|
if data is None:
|
||||||
|
raise BadRequest
|
||||||
|
except BadRequest:
|
||||||
|
return jsonify({"error": "Invalid JSON"}), 400
|
||||||
|
else:
|
||||||
|
|
||||||
|
data = request.form.to_dict()
|
||||||
|
|
||||||
|
doc_uuid=data.get("doc_uuid")
|
||||||
|
if not doc_uuid:
|
||||||
|
return jsonify({"error": "Missing 'doc_uuid' in request"}), 400
|
||||||
|
filter_condition = models.Filter(
|
||||||
|
must=[
|
||||||
|
models.FieldCondition(
|
||||||
|
key="doc_id",
|
||||||
|
match=models.MatchValue(value=doc_uuid)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = Qdrant.get_client().delete(
|
||||||
|
|
||||||
|
points_selector=models.FilterSelector(
|
||||||
|
filter=filter_condition
|
||||||
|
),
|
||||||
|
wait=True
|
||||||
|
)
|
||||||
|
if result and result.status == "completed":
|
||||||
|
return jsonify({"message": f"Deleted all points with doc_id = {doc_uuid}"}), 200
|
||||||
|
else:
|
||||||
|
return jsonify({"warning": "Deletion request did not complete successfully"}), 500
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
@app.post("/delete")
|
@app.post("/delete")
|
||||||
def delete():
|
def delete():
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user