-
Notifications
You must be signed in to change notification settings - Fork 960
Cog 656 deployment state #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f3ce7be
feat: Add ability to send directories with data to cognee
dexters1 d4e2eb7
fix: fix existing edge check
dexters1 d9d90d9
chore: Remove comments from code
dexters1 ff9fd90
feat: Add directory resolution as step in cognee add function
dexters1 9b4af85
fix: Resolve issue with text being submitted as data
dexters1 3a1229c
Merge branch 'fix-pgvector-search' of github.com:topoteretes/cognee i…
dexters1 659a995
Merge branch 'dev' of github.com:topoteretes/cognee into COG-656-depl…
dexters1 7100a49
feat: Add resolving of directories as task for the add pipeline
dexters1 92d0122
fix: Remove data handling based on type in resolving directory function
dexters1 eddfc17
fix: Rewrite endpoint to add users to groups
dexters1 b8ba436
fix: Resolve issue with adding permissions to groups
dexters1 1180839
feat: Add error handling in case user is already part of database and…
dexters1 43187e4
feat: Add user verification for accessing data
dexters1 9c3e242
feat: Add compute search to cognee
dexters1 c90d90a
Merge branch 'dev' into COG-656-deployment-state
dexters1 67585d0
feat: Add simple instruction for system prompt
dexters1 11634cb
feat: Add unauth access error to getting data
dexters1 924759a
refactor: Rename query compute to query completion
dexters1 35b1f7d
chore: Update typo in code
dexters1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
47 changes: 32 additions & 15 deletions
47
cognee/api/v1/permissions/routers/get_permissions_router.py
This file contains hidden or 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 hidden or 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 hidden or 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. Be as brief as possible. |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ | |
|
|
||
| from .exceptions import ( | ||
| UnstructuredLibraryImportError, | ||
| UnauthorizedDataAccessError, | ||
| ) | ||
This file contains hidden or 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 hidden or 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 hidden or 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,11 @@ | ||
| from datetime import datetime, timezone | ||
| from sqlalchemy import Column, ForeignKey, DateTime, UUID | ||
| from cognee.infrastructure.databases.relational import Base | ||
|
|
||
| class GroupPermission(Base): | ||
| __tablename__ = "group_permissions" | ||
|
|
||
| created_at = Column(DateTime(timezone = True), default = lambda: datetime.now(timezone.utc)) | ||
dexters1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| group_id = Column(UUID, ForeignKey("groups.id"), primary_key = True) | ||
| permission_id = Column(UUID, ForeignKey("permissions.id"), primary_key = True) | ||
This file contains hidden or 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,5 +1,7 @@ | ||
| from .User import User | ||
| from .Group import Group | ||
| from .UserGroup import UserGroup | ||
| from .GroupPermission import GroupPermission | ||
| from .Resource import Resource | ||
| from .Permission import Permission | ||
| from .ACL import ACL |
This file contains hidden or 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 @@ | ||
| from .query_completion import query_completion |
This file contains hidden or 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,9 @@ | ||
| """ | ||
| Custom exceptions for the Cognee API. | ||
|
|
||
| This module defines a set of exceptions for handling various compute errors | ||
| """ | ||
|
|
||
| from .exceptions import ( | ||
| NoRelevantDataFound, | ||
| ) |
This file contains hidden or 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,11 @@ | ||
| from cognee.exceptions import CogneeApiError | ||
| from fastapi import status | ||
|
|
||
| class NoRelevantDataFound(CogneeApiError): | ||
| def __init__( | ||
| self, | ||
| message: str = "Search did not find any data.", | ||
| name: str = "NoRelevantDataFound", | ||
| status_code=status.HTTP_404_NOT_FOUND, | ||
| ): | ||
| super().__init__(message, name, status_code) |
This file contains hidden or 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,36 @@ | ||
| 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 | ||
|
|
||
|
|
||
| async def query_completion(query: str) -> list: | ||
| """ | ||
| Parameters: | ||
| - query (str): The query string to compute. | ||
| Returns: | ||
| - list: Answer to the query. | ||
| """ | ||
| vector_engine = get_vector_engine() | ||
|
|
||
| found_chunks = await vector_engine.search("document_chunk_text", query, limit = 1) | ||
|
|
||
| if len(found_chunks) == 0: | ||
| raise NoRelevantDataFound | ||
dexters1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| args = { | ||
| "question": query, | ||
| "context": found_chunks[0].payload["text"], | ||
| } | ||
| user_prompt = render_prompt("context_for_question.txt", args) | ||
| system_prompt = read_query_prompt("answer_simple_question.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, | ||
| ) | ||
dexters1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return [computed_answer] | ||
This file contains hidden or 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 hidden or 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,37 @@ | ||
| import os | ||
| from typing import List, Union, BinaryIO | ||
|
|
||
| async def resolve_data_directories(data: Union[BinaryIO, List[BinaryIO], str, List[str]], include_subdirectories: bool = True): | ||
| """ | ||
| Resolves directories by replacing them with their contained files. | ||
| Args: | ||
| data: A single file, directory, or binary stream, or a list of such items. | ||
| include_subdirectories: Whether to include files in subdirectories recursively. | ||
| Returns: | ||
| A list of resolved files and binary streams. | ||
| """ | ||
| # Ensure `data` is a list | ||
| if not isinstance(data, list): | ||
| data = [data] | ||
|
|
||
| resolved_data = [] | ||
|
|
||
| for item in data: | ||
| if isinstance(item, str): # Check if the item is a path | ||
| if os.path.isdir(item): # If it's a directory | ||
| if include_subdirectories: | ||
| # Recursively add all files in the directory and subdirectories | ||
| for root, _, files in os.walk(item): | ||
| resolved_data.extend([os.path.join(root, f) for f in files]) | ||
| else: | ||
| # Add all files (not subdirectories) in the directory | ||
| resolved_data.extend( | ||
| [os.path.join(item, f) for f in os.listdir(item) if os.path.isfile(os.path.join(item, f))] | ||
| ) | ||
dexters1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else: # If it's a file or text add it directly | ||
| resolved_data.append(item) | ||
| else: # If it's not a string add it directly | ||
| resolved_data.append(item) | ||
dexters1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return resolved_data | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.