-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/cog-971-preparing-swe-bench-run' of https://git…
…hub.com/topoteretes/cognee into feature/cog-971-preparing-swe-bench-run
- Loading branch information
Showing
13 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
cognee/infrastructure/llm/prompts/answer_simple_question_restricted.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Answer the question using the provided context. If the provided context is not connected to the question, just answer "The provided knowledge base does not contain the answer to the question". Be as brief as possible. |
2 changes: 2 additions & 0 deletions
2
cognee/infrastructure/llm/prompts/graph_context_for_question.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The question is: `{{ question }}` | ||
and here is the context provided with a set of relationships from a knowledge graph separated by \n---\n each represented as node1 -- relation -- node2 triplet: `{{ context }}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .query_completion import query_completion | ||
from .graph_query_completion import graph_query_completion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from cognee.infrastructure.databases.vector import get_vector_engine | ||
from cognee.tasks.completion.exceptions import NoRelevantDataFound | ||
from cognee.infrastructure.llm.get_llm_client import get_llm_client | ||
from cognee.infrastructure.llm.prompts import read_query_prompt, render_prompt | ||
from cognee.modules.retrieval.brute_force_triplet_search import brute_force_triplet_search | ||
|
||
|
||
def retrieved_edges_to_string(retrieved_edges: list) -> str: | ||
edge_strings = [] | ||
for edge in retrieved_edges: | ||
node1_string = edge.node1.attributes.get("text") or edge.node1.attributes.get("name") | ||
node2_string = edge.node2.attributes.get("text") or edge.node2.attributes.get("name") | ||
edge_string = edge.attributes["relationship_type"] | ||
edge_str = f"{node1_string} -- {edge_string} -- {node2_string}" | ||
edge_strings.append(edge_str) | ||
return "\n---\n".join(edge_strings) | ||
|
||
|
||
async def graph_query_completion(query: str) -> list: | ||
""" | ||
Parameters: | ||
- query (str): The query string to compute. | ||
Returns: | ||
- list: Answer to the query. | ||
""" | ||
found_triplets = await brute_force_triplet_search(query, top_k=5) | ||
|
||
if len(found_triplets) == 0: | ||
raise NoRelevantDataFound | ||
|
||
args = { | ||
"question": query, | ||
"context": retrieved_edges_to_string(found_triplets), | ||
} | ||
user_prompt = render_prompt("graph_context_for_question.txt", args) | ||
system_prompt = read_query_prompt("answer_simple_question_restricted.txt") | ||
|
||
llm_client = get_llm_client() | ||
computed_answer = await llm_client.acreate_structured_output( | ||
text_input=user_prompt, | ||
system_prompt=system_prompt, | ||
response_model=str, | ||
) | ||
|
||
return [computed_answer] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters