-
Notifications
You must be signed in to change notification settings - Fork 188
perf(core): reuse written note content after writes #717
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
Changes from 1 commit
f853e61
a198ba9
5174b18
8ad2a6b
1bd1aad
e7b75c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -306,8 +306,11 @@ async def create_entity( | |
| ): | ||
| if fast: | ||
| entity = await entity_service.fast_write_entity(data) | ||
| written_content = None | ||
| else: | ||
| entity = await entity_service.create_entity(data) | ||
| write_result = await entity_service.create_entity_with_content(data) | ||
| entity = write_result.entity | ||
| written_content = write_result.content | ||
|
|
||
| if fast: | ||
| with telemetry.scope( | ||
|
|
@@ -329,7 +332,7 @@ async def create_entity( | |
| action="create_entity", | ||
| phase="search_index", | ||
| ): | ||
| await search_service.index_entity(entity) | ||
| await search_service.index_entity(entity, content=written_content) | ||
| with telemetry.scope( | ||
| "api.knowledge.create_entity.vector_sync", | ||
| domain="knowledge", | ||
|
|
@@ -352,8 +355,12 @@ async def create_entity( | |
| domain="knowledge", | ||
| action="create_entity", | ||
| phase="read_content", | ||
| source="file" if fast else "memory", | ||
| ): | ||
| content = await file_service.read_file_content(entity.file_path) | ||
| if fast: | ||
| content = await file_service.read_file_content(entity.file_path) | ||
| else: | ||
| content = written_content | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For non-fast writes, the response content now comes from in-memory Useful? React with 👍 / 👎. |
||
| result = result.model_copy(update={"content": content}) | ||
|
|
||
| logger.info( | ||
|
|
@@ -421,13 +428,18 @@ async def update_entity_by_id( | |
| ): | ||
| if fast: | ||
| entity = await entity_service.fast_write_entity(data, external_id=entity_id) | ||
| written_content = None | ||
| response.status_code = 200 if existing else 201 | ||
| else: | ||
| if existing: | ||
| entity = await entity_service.update_entity(existing, data) | ||
| write_result = await entity_service.update_entity_with_content(existing, data) | ||
| entity = write_result.entity | ||
| written_content = write_result.content | ||
| response.status_code = 200 | ||
| else: | ||
| entity = await entity_service.create_entity(data) | ||
| write_result = await entity_service.create_entity_with_content(data) | ||
| entity = write_result.entity | ||
| written_content = write_result.content | ||
| if entity.external_id != entity_id: | ||
| entity = await entity_repository.update( | ||
| entity.id, | ||
|
|
@@ -461,7 +473,7 @@ async def update_entity_by_id( | |
| action="update_entity", | ||
| phase="search_index", | ||
| ): | ||
| await search_service.index_entity(entity) | ||
| await search_service.index_entity(entity, content=written_content) | ||
| with telemetry.scope( | ||
| "api.knowledge.update_entity.vector_sync", | ||
| domain="knowledge", | ||
|
|
@@ -484,8 +496,12 @@ async def update_entity_by_id( | |
| domain="knowledge", | ||
| action="update_entity", | ||
| phase="read_content", | ||
| source="file" if fast else "memory", | ||
| ): | ||
| content = await file_service.read_file_content(entity.file_path) | ||
| if fast: | ||
| content = await file_service.read_file_content(entity.file_path) | ||
| else: | ||
| content = written_content | ||
| result = result.model_copy(update={"content": content}) | ||
|
|
||
| logger.info( | ||
|
|
@@ -563,16 +579,19 @@ async def edit_entity_by_id( | |
| find_text=data.find_text, | ||
| expected_replacements=data.expected_replacements, | ||
| ) | ||
| written_content = None | ||
| else: | ||
| identifier = entity.permalink or entity.file_path | ||
| updated_entity = await entity_service.edit_entity( | ||
| write_result = await entity_service.edit_entity_with_content( | ||
| identifier=identifier, | ||
| operation=data.operation, | ||
| content=data.content, | ||
| section=data.section, | ||
| find_text=data.find_text, | ||
| expected_replacements=data.expected_replacements, | ||
| ) | ||
| updated_entity = write_result.entity | ||
| written_content = write_result.content | ||
|
|
||
| if fast: | ||
| with telemetry.scope( | ||
|
|
@@ -594,7 +613,7 @@ async def edit_entity_by_id( | |
| action="edit_entity", | ||
| phase="search_index", | ||
| ): | ||
| await search_service.index_entity(updated_entity) | ||
| await search_service.index_entity(updated_entity, content=written_content) | ||
| with telemetry.scope( | ||
| "api.knowledge.edit_entity.vector_sync", | ||
| domain="knowledge", | ||
|
|
@@ -617,8 +636,12 @@ async def edit_entity_by_id( | |
| domain="knowledge", | ||
| action="edit_entity", | ||
| phase="read_content", | ||
| source="file" if fast else "memory", | ||
| ): | ||
| content = await file_service.read_file_content(updated_entity.file_path) | ||
| if fast: | ||
| content = await file_service.read_file_content(updated_entity.file_path) | ||
| else: | ||
| content = written_content | ||
| result = result.model_copy(update={"content": content}) | ||
|
|
||
| logger.info( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The non-fast create path now calls
search_service.index_entity(entity, content=written_content), butwritten_contentis full serialized markdown fromdump_frontmatter(...)increate_entity_with_content, while the previous path indexedread_entity_content(...)output (content normalized by the markdown processor). This change makes YAML/frontmatter tokens part of indexed content, which can materially degrade search relevance by injecting metadata noise into every note; pass normalized body content (or keep the existing read/normalize path) before indexing.Useful? React with 👍 / 👎.