fix: Remove creation of default user during search (#1455)
<!-- .github/pull_request_template.md --> ## Description Removed default user creation during brute force search. Even when a user is provided to search it's not forwarded to the Retrievers, the retrievers always created a default user and sent telemetry as the default user which is inaccurate, they also create a default user even when there shouldn't be one. if this information is necessary for telemetry we should forward the user information that was sent through search through the retrievers and not always create a default user ## 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) - [x] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Other (please specify): ## Changes Made Removed user as parameter from brute force search, removed default user creation that was supplied as parameter to brute force search ## Testing Ran simple example, waiting for CI/CD results ## Pre-submission Checklist <!-- Please check all boxes that apply before submitting your PR --> - [x] **I have tested my changes thoroughly before submitting this PR** - [x] **This PR contains minimal changes necessary to address the issue/feature** - [x] 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 - [x] I have searched existing PRs to ensure this change hasn't been submitted already - [ ] I have linked any relevant issues in the description - [x] My commits have clear and descriptive messages ## 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:
commit
8246a6a02f
7 changed files with 2 additions and 31 deletions
|
|
@ -42,14 +42,12 @@ class TripletSearchContextProvider(BaseContextProvider):
|
|||
self,
|
||||
entities: List[DataPoint],
|
||||
query: str,
|
||||
user: User,
|
||||
memory_fragment: CogneeGraph,
|
||||
) -> List:
|
||||
"""Creates search tasks for valid entities."""
|
||||
tasks = [
|
||||
brute_force_triplet_search(
|
||||
query=f"{entity_text} {query}",
|
||||
user=user,
|
||||
top_k=self.top_k,
|
||||
collections=self.collections,
|
||||
properties_to_project=self.properties_to_project,
|
||||
|
|
@ -84,9 +82,8 @@ class TripletSearchContextProvider(BaseContextProvider):
|
|||
if not entities:
|
||||
return "No entities provided for context search."
|
||||
|
||||
user = await get_default_user()
|
||||
memory_fragment = await get_memory_fragment(self.properties_to_project)
|
||||
search_tasks = self._get_search_tasks(entities, query, user, memory_fragment)
|
||||
search_tasks = self._get_search_tasks(entities, query, memory_fragment)
|
||||
|
||||
if not search_tasks:
|
||||
return "No valid entities found for context search."
|
||||
|
|
|
|||
|
|
@ -93,11 +93,8 @@ class GraphCompletionRetriever(BaseGraphRetriever):
|
|||
for field_name in index_fields:
|
||||
vector_index_collections.append(f"{subclass.__name__}_{field_name}")
|
||||
|
||||
user = await get_default_user()
|
||||
|
||||
found_triplets = await brute_force_triplet_search(
|
||||
query,
|
||||
user=user,
|
||||
top_k=self.top_k,
|
||||
collections=vector_index_collections or None,
|
||||
node_type=self.node_type,
|
||||
|
|
|
|||
|
|
@ -89,7 +89,6 @@ async def get_memory_fragment(
|
|||
|
||||
async def brute_force_triplet_search(
|
||||
query: str,
|
||||
user: User,
|
||||
top_k: int = 5,
|
||||
collections: Optional[List[str]] = None,
|
||||
properties_to_project: Optional[List[str]] = None,
|
||||
|
|
@ -102,7 +101,6 @@ async def brute_force_triplet_search(
|
|||
|
||||
Args:
|
||||
query (str): The search query.
|
||||
user (User): The user performing the search.
|
||||
top_k (int): The number of top results to retrieve.
|
||||
collections (Optional[List[str]]): List of collections to query.
|
||||
properties_to_project (Optional[List[str]]): List of properties to project.
|
||||
|
|
@ -139,8 +137,6 @@ async def brute_force_triplet_search(
|
|||
|
||||
query_vector = (await vector_engine.embedding_engine.embed_text([query]))[0]
|
||||
|
||||
send_telemetry("cognee.brute_force_triplet_search EXECUTION STARTED", user.id)
|
||||
|
||||
async def search_in_collection(collection_name: str):
|
||||
try:
|
||||
return await vector_engine.search(
|
||||
|
|
@ -176,20 +172,14 @@ async def brute_force_triplet_search(
|
|||
|
||||
results = await memory_fragment.calculate_top_triplet_importances(k=top_k)
|
||||
|
||||
send_telemetry("cognee.brute_force_triplet_search EXECUTION COMPLETED", user.id)
|
||||
|
||||
return results
|
||||
|
||||
except CollectionNotFoundError:
|
||||
return []
|
||||
except Exception as error:
|
||||
logger.error(
|
||||
"Error during brute force search for user: %s, query: %s. Error: %s",
|
||||
user.id,
|
||||
"Error during brute force search for query: %s. Error: %s",
|
||||
query,
|
||||
error,
|
||||
)
|
||||
send_telemetry(
|
||||
"cognee.brute_force_triplet_search EXECUTION FAILED", user.id, {"error": str(error)}
|
||||
)
|
||||
raise error
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import cognee
|
|||
from cognee.low_level import setup, DataPoint
|
||||
from cognee.tasks.storage import add_data_points
|
||||
from cognee.modules.graph.utils import resolve_edges_to_text
|
||||
from cognee.infrastructure.databases.exceptions import DatabaseNotCreatedError
|
||||
from cognee.modules.retrieval.graph_completion_context_extension_retriever import (
|
||||
GraphCompletionContextExtensionRetriever,
|
||||
)
|
||||
|
|
@ -165,9 +164,6 @@ class TestGraphCompletionWithContextExtensionRetriever:
|
|||
|
||||
retriever = GraphCompletionContextExtensionRetriever()
|
||||
|
||||
with pytest.raises(DatabaseNotCreatedError):
|
||||
await retriever.get_context("Who works at Figma?")
|
||||
|
||||
await setup()
|
||||
|
||||
context = await retriever.get_context("Who works at Figma?")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import cognee
|
|||
from cognee.low_level import setup, DataPoint
|
||||
from cognee.modules.graph.utils import resolve_edges_to_text
|
||||
from cognee.tasks.storage import add_data_points
|
||||
from cognee.infrastructure.databases.exceptions import DatabaseNotCreatedError
|
||||
from cognee.modules.retrieval.graph_completion_cot_retriever import GraphCompletionCotRetriever
|
||||
|
||||
|
||||
|
|
@ -158,9 +157,6 @@ class TestGraphCompletionCoTRetriever:
|
|||
|
||||
retriever = GraphCompletionCotRetriever()
|
||||
|
||||
with pytest.raises(DatabaseNotCreatedError):
|
||||
await retriever.get_context("Who works at Figma?")
|
||||
|
||||
await setup()
|
||||
|
||||
context = await retriever.get_context("Who works at Figma?")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import cognee
|
|||
from cognee.low_level import setup, DataPoint
|
||||
from cognee.modules.graph.utils import resolve_edges_to_text
|
||||
from cognee.tasks.storage import add_data_points
|
||||
from cognee.infrastructure.databases.exceptions import DatabaseNotCreatedError
|
||||
from cognee.modules.retrieval.graph_completion_retriever import GraphCompletionRetriever
|
||||
|
||||
|
||||
|
|
@ -218,9 +217,6 @@ class TestGraphCompletionRetriever:
|
|||
|
||||
retriever = GraphCompletionRetriever()
|
||||
|
||||
with pytest.raises(DatabaseNotCreatedError):
|
||||
await retriever.get_context("Who works at Figma?")
|
||||
|
||||
await setup()
|
||||
|
||||
context = await retriever.get_context("Who works at Figma?")
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ async def main():
|
|||
query = "When was Kamala Harris in office?"
|
||||
triplets = await brute_force_triplet_search(
|
||||
query=query,
|
||||
user=user,
|
||||
top_k=3,
|
||||
collections=["graphitinode_content", "graphitinode_name", "graphitinode_summary"],
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue