TRIPLET_EXTRACT_PT = ("Some text is provided below. Given the text, ""extract up to knowledge triplets as more as possible ""in the form of (subject, predicate, object).\n""Avoid stopwords.\n""---------------------\n""Example:\n""Text: Alice is Bob's mother.\n""Triplets:\n(Alice, is mother of, Bob)\n" ...TL;DR..."Text: Philz is a coffee shop founded in Berkeley in 1982.\n""Triplets:(Philz, is, coffee shop)\n(Philz, founded in, Berkeley)\n(Philz, founded in, 1982)\n""---------------------\n""Text: {text}\n""Triplets:\n")
KEYWORD_EXTRACT_PT = ( "A question is provided below. Given the question, extract up to " "keywords from the text. Focus on extracting the keywords that we can use" "to best lookup answers to the question.\n" "Generate as more as possible synonyms oraliasof the keywords " "considering possible cases of capitalization, pluralization, " "common expressions, etc.\n" "Avoid stopwords.\n" "Provide the keywords and synonyms in comma-separated format." "Formatted keywords and synonyms text should be separated by a semicolon.\n" "---------------------\n""Example:\n""Text: Alice is Bob's mother.\n""Keywords:\nAlice,mother,Bob;mummy\n""Text: Philz is a coffee shop founded in Berkeley in 1982.\n""Keywords:\nPhilz,coffee shop,Berkeley,1982;coffee bar,coffee house\n""---------------------\n""Text: {text}\n""Keywords:\n")
asyncdefasimilar_search_with_scores( self, text, topk, score_threshold: float, filters: Optional[MetadataFilters] = None,) -> List[Chunk]:"""Search neighbours on knowledge graph."""ifnot filters: logger.info("Filters on knowledge graph not supported yet") # extract keywords and explore graph store keywords = await self._keyword_extractor.extract(text) subgraph = self._graph_store.explore(keywords, limit=topk) logger.info(f"Search subgraph from {len(keywords)} keywords") content = ("The following vertices and edges data after [Subgraph Data] ""are retrieved from the knowledge graph based on the keywords:\n"f"Keywords:\n{','.join(keywords)}\n""---------------------\n""You can refer to the sample vertices and edges to understand ""the real knowledge graph data provided by [Subgraph Data].\n""Sample vertices:\n""(alice)\n""Sample edges:\n""(alice)-[reward]->(alice)\n""---------------------\n"f"Subgraph Data:\n{subgraph.format()}\n" )return [Chunk(content=content, metadata=subgraph.schema())]