refactor: make cypher query optional (#1418)

<!-- .github/pull_request_template.md -->

## Description
Make Cypher search optional

## Type of Change
<!-- Please check the relevant option -->
- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Code refactoring
- [ ] Performance improvement
- [x] Other (please specify):
Security upgrade

## Changes Made
Made cypher search optional for security reasons

## Testing
Tried running cypher queries with feature turned on and off

## Screenshots/Videos (if applicable)
<!-- Add screenshots or videos to help explain your changes -->

## Pre-submission Checklist
<!-- Please check all boxes that apply before submitting your PR -->
- [ ] **I have tested my changes thoroughly before submitting this PR**
- [ ] **This PR contains minimal changes necessary to address the
issue/feature**
- [ ] My code follows the project's coding standards and style
guidelines
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added necessary documentation (if applicable)
- [ ] All new and existing tests pass
- [ ] I have searched existing PRs to ensure this change hasn't been
submitted already
- [ ] I have linked any relevant issues in the description
- [ ] My commits have clear and descriptive messages

## Related Issues
<!-- Link any related issues using "Fixes #issue_number" or "Relates to
#issue_number" -->

## Additional Notes
<!-- Add any additional notes, concerns, or context for reviewers -->

## DCO Affirmation
I affirm that all code in every commit of this pull request conforms to
the terms of the Topoteretes Developer Certificate of Origin.
This commit is contained in:
Igor Ilic 2025-09-17 10:56:35 +02:00 committed by GitHub
parent fc49725126
commit e849e12567
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View file

@ -121,6 +121,9 @@ ACCEPT_LOCAL_FILE_PATH=True
# This protects against Server Side Request Forgery when proper infrastructure is not in place. # This protects against Server Side Request Forgery when proper infrastructure is not in place.
ALLOW_HTTP_REQUESTS=True ALLOW_HTTP_REQUESTS=True
# When set to false don't allow cypher search to be used in Cognee.
ALLOW_CYPHER_QUERY=True
# When set to False errors during data processing will be returned as info but not raised to allow handling of faulty documents # When set to False errors during data processing will be returned as info but not raised to allow handling of faulty documents
RAISE_INCREMENTAL_LOADING_ERRORS=True RAISE_INCREMENTAL_LOADING_ERRORS=True

View file

@ -1,3 +1,4 @@
import os
from typing import Callable, List, Optional, Type from typing import Callable, List, Optional, Type
from cognee.modules.engine.models.node_set import NodeSet from cognee.modules.engine.models.node_set import NodeSet
@ -160,6 +161,12 @@ async def get_search_type_tools(
if query_type is SearchType.FEELING_LUCKY: if query_type is SearchType.FEELING_LUCKY:
query_type = await select_search_type(query_text) query_type = await select_search_type(query_text)
if (
query_type in [SearchType.CYPHER, SearchType.NATURAL_LANGUAGE]
and os.getenv("ALLOW_CYPHER_QUERY", "true").lower() == "false"
):
raise UnsupportedSearchTypeError("Cypher query search types are disabled.")
search_type_tools = search_tasks.get(query_type) search_type_tools = search_tasks.get(query_type)
if not search_type_tools: if not search_type_tools: