(self, text, topK=5, where=None, where_document=None)
| 88 | self.redisCaching = RedisCaching() |
| 89 | |
| 90 | def query(self, text, topK=5, where=None, where_document=None): |
| 91 | # where={"metadata_field": "is_equal_to_this"}, |
| 92 | # where_document={"$contains": "search_string"} |
| 93 | if self.need_redis: |
| 94 | starttime = time.time() |
| 95 | res = self.query_preprocessing(text, top_k=topK) |
| 96 | if res is not None: |
| 97 | if len(res) >= 1: |
| 98 | return res |
| 99 | if where is None: |
| 100 | if where_document is None: |
| 101 | result = self.collection.query( |
| 102 | query_texts=[text], |
| 103 | n_results=topK |
| 104 | ) |
| 105 | else: |
| 106 | result = self.collection.query( |
| 107 | query_texts=[text], |
| 108 | n_results=topK, |
| 109 | ) |
| 110 | else: |
| 111 | if where_document is None: |
| 112 | result = self.collection.query( |
| 113 | query_texts=[text], |
| 114 | n_results=topK, |
| 115 | where=where |
| 116 | ) |
| 117 | else: |
| 118 | result = self.collection.query( |
| 119 | query_texts=[text], |
| 120 | n_results=topK, |
| 121 | where=where |
| 122 | ) |
| 123 | |
| 124 | result = self.processResult(query=[text], result=result) |
| 125 | """ |
| 126 | result : [[]] 第一层为查询的数量,现在为1,第二层为每一次查询的相似度结果 |
| 127 | """ |
| 128 | return result |
| 129 | |
| 130 | def batchQuery(self, texts, topK=5, where=None, where_document=None): |
| 131 | # where={"metadata_field": "is_equal_to_this"}, |
no test coverage detected