def learn(self, fact: str = None) -> Response: """Learns a new fact.""" if fact is None: return Response.error(500, "Empty fact provided to learn.") if self.index is None: return Response.error(500, "Unable to initialize QA index.") res = self.index.embed(fact) if res.error: # Steamship error messages can be passed straight # back to the user return Response(error=res.error) return Response(json=res.data)
def query(self, query: str = None, k: int = 1) -> Response: """Learns a new fact.""" if query is None: return Response.error(500, "Empty query provided.") if self.index is None: return Response.error(500, "Unable to initialize QA index.") res = self.index.query(query=query, k=k) if res.error: # Steamship error messages can be passed straight # back to the user return Response(error=res.error) return Response(json=res.data)