def _exact_match_vids()

in hugegraph-llm/src/hugegraph_llm/operators/index_op/semantic_id_query.py [0:0]


    def _exact_match_vids(self, keywords: List[str]) -> Tuple[List[str], List[str]]:
        assert keywords, "keywords can't be empty, please check the logic"
        # TODO: we should add a global GraphSchemaCache to avoid calling the server every time
        vertex_label_num = len(self._client.schema().getVertexLabels())
        possible_vids = set(keywords)
        for i in range(vertex_label_num):
            possible_vids.update([f"{i + 1}:{keyword}" for keyword in keywords])

        vids_str = ",".join([f"'{vid}'" for vid in possible_vids])
        resp = self._client.gremlin().exec(SemanticIdQuery.ID_QUERY_TEMPL.format(vids_str=vids_str))
        searched_vids = [v['id'] for v in resp['data']]

        unsearched_keywords = set(keywords)
        for vid in searched_vids:
            for keyword in unsearched_keywords:
                if keyword in vid:
                    unsearched_keywords.remove(keyword)
                    break
        return searched_vids, list(unsearched_keywords)