From a08759ff958a04b097645f2a823a0e15fac8d039 Mon Sep 17 00:00:00 2001 From: DylanAlloy Date: Wed, 20 Dec 2023 16:14:22 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20fix(wip):=20invocation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- magnet/ron/milvus.py | 7 ++++--- magnet/ron/utils/prompts.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/magnet/ron/milvus.py b/magnet/ron/milvus.py index 3de3d57..db642b0 100644 --- a/magnet/ron/milvus.py +++ b/magnet/ron/milvus.py @@ -33,14 +33,15 @@ def embed_and_store(self, payload, verbose=False): ]) except Exception as e: _f('fatal',e) - def search(self, payload, cb=None): + def search(self, payload, limit=100, cb=None): + payload = {'text':payload} payload['embedding'] = self.model.encode(payload['text'], normalize_embeddings=True) self.db.collection.load() _results = self.db.collection.search( data=[payload['embedding']], # Embeded search value anns_field="embedding", # Search across embeddings param={}, - limit = 100, # Limit to top_k results per search + limit = limit, # Limit to top_k results per search output_fields=['text', 'document'] ) results = [] @@ -52,7 +53,7 @@ def search(self, payload, cb=None): , 'distance': hit.distance }) if cb: - cb(results) + return cb(payload['text'], results) else: return results def delete(self, name=None): diff --git a/magnet/ron/utils/prompts.py b/magnet/ron/utils/prompts.py index 5605fd9..d54a515 100644 --- a/magnet/ron/utils/prompts.py +++ b/magnet/ron/utils/prompts.py @@ -2,7 +2,7 @@ class Prompts: def __init__(self): return def qa_ref(self, docs: list = [], q: str = None): - docs = '\n'.join([f"Document: {d}\nText: {t}" for (d, t) in [tuple(x.values()) for x in docs]]) + docs = '\n'.join([f"Document: {d}\nText: {t}" for (t, d, c) in [tuple(x.values()) for x in docs]]) return """Create a concise and informative answer (no more than 50 words) for a given question based solely on the given documents. You must only use information from the given documents. Use an unbiased and journalistic tone. Do not repeat text. Cite the documents using Document[name] notation. If multiple documents contain the answer, cite those documents like ‘as stated in Document[name], Document[name], etc.’. If the documents do not contain the answer to the question, say that ‘answering is not possible given the available information.’ [DOCUMENTS] Question: [QUERY]; Answer: """ \