###### Abstract  
Knowledge graph (KG) reasoning aims to obtain new knowledge based on existing data. Utilizing large language models (LLMs) through in-context learning for KG reasoning has become a significant direction. However, existing methods mainly extract in-context triples by manually defined standards (such as the neighbors that are directly linked with the query triple), without considering whether they are useful for LLM reasoning. Furthermore, the triples beyond the neighbors can also provide important clues for reasoning. Therefore, it is necessary to extract more useful in-context triples of LLMs for KG reasoning. This paper proposes a rule-and-reinforce in-context triple extraction method to enhance the in-context learning of LLMs for KG reasoning. First, we collect the in-context triples specific to each query triple with the guidance of logical rules, and a neural extractor is pre-trained by the collected triples. Subsequently, the feedback of LLMs is collected as rewards to further optimize the extractor, where the policy gradient is utilized to encourage the extractor to explore more useful triples that yield higher rewards. The experimental results on five different knowledge graphs demonstrate that the proposed method can effectively improve the reasoning performance of LLMs. Compared to the traditional reasoning method AnyBURL, the greatest improvement is 0.147 on Hits@10, FB15k-237. 2020 IEEEexample:BSTcontrol  
22 December 20241  
thereby constraining the reasoning effectiveness of these methods [8; 9]. As illustrated in the example shown in Figure 1, given the query triple \"([PERSON], lives in country,? )\", a logical rule can be mined from the knowledge graph through logical rule learning: \"(x, lives in country, \(w\))\(\leftarrow\)(x, works at, y)\(\wedge\)(y, located in state, z)\(\wedge\)(z, state in country, \(w\))\". This logical rule indicates that if there exists a path consisting \"works at, located in state, state in country\" between entities \(x\) and \(w\), then we can infer that the relation \"lives in country\" exists between \(x\) and \(w\). However, as shown in Figure 1c, by analyzing the existing triples in the knowledge graph, it can be found that due to the incompleteness problem, the relation \"state in country\" (depicted with the dashed line) between the entities \"Colorado\" and \"USA\" does not exist. Therefore, the path represented by the aforementioned logical rule is not valid in the existing data, ultimately leading to an incomplete reasoning process. In recent years, the emergence of large language models (LLMs) has sparked a new wave in the field of artificial intelligence. LLMs, equipped with millions of parameters and trained on large-scale corpora, have acquired immense knowledge and demonstrated superior performance across various natural language tasks, such as machine translation [10], text analysis [11], and intelligent question answering [12]. Consequently, the knowledge implied in LLMs may alleviate the limitations imposed by the incompleteness of knowledge graphs. As a result, leveraging LLMs for knowledge graph reasoning has emerged as a novel direction. To better adapt the LLMs to reasoning tasks, in-context learning is utilized in the process of reasoning, the main idea is to retrieve relevant triples from existing knowledge graphs based on the given query triple, incorporating them into the prompt [13; 14; 15]. However, existing methods mainly extract in-context triples from KGs by manually defined standards (such as the neighbors that are directly linked with the given query triple), without considering whether these triples are truly useful for the reasoning of LLMs. In fact, triples directly linked to the query entity may not necessarily be effective for the reasoning of the given query, while triples not directly connected to the query entity may potentially provide crucial reasoning clues. As depicted in Figure 1, for the given  
Figure 1: An example of reasoning on incomplete knowledge graphs. query \"([PERSON], lives in country,?