Implementation:ALwrity ALwrity save and track text content
| Knowledge Sources | |
|---|---|
| Domains | LinkedIn, Asset_Tracking, File_Storage |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for saving text content to disk and tracking it in the asset library with SIF indexing, provided by the ALwrity text asset tracker utility.
Description
The save_and_track_text_content function is stage 5 of the LinkedIn Content Pipeline. It saves generated text content (LinkedIn post, blog, etc.) to the user's workspace on disk (workspace/users/user_{id}/media/{module}_text/), generates a safe filename from the title, and registers the asset in the content asset library via save_asset_to_library. The asset is then indexed to the SIF (semantic indexing framework) for future retrieval. If the user's workspace cannot be resolved, it falls back to a default data/media directory.
Usage
Import this function when:
- Generated text content must be persisted to disk and tracked as a library asset.
- SIF indexing should be triggered for the saved content.
- A user workspace path should be used, with a fallback to a default directory.
Code Reference
Source Location
- Repository: ALwrity
- File: backend/utils/text_asset_tracker.py (L16-184)
Signature
def save_and_track_text_content(
db: Session,
user_id: str,
content: str,
source_module: str,
title: str,
description: Optional[str] = None,
prompt: Optional[str] = None,
tags: Optional[list] = None,
asset_metadata: Optional[Dict[str, Any]] = None,
base_dir: Optional[Path] = None,
subdirectory: Optional[str] = None,
file_extension: str = ".txt",
) -> Optional[int]:
"""
Save text content to disk and track it in the asset library.
Args:
db: Database session.
user_id: Clerk user ID.
content: Text content to save.
source_module: Source module name (e.g. 'linkedin_writer').
title: Title for the asset.
description: Description of the content.
prompt: Original prompt used for generation.
tags: List of tags for search/filtering.
asset_metadata: Additional metadata.
base_dir: Base directory (defaults to workspace media dir).
subdirectory: Optional subdirectory (e.g. 'posts').
file_extension: File extension (.txt, .md).
Returns:
Asset ID if successful, None otherwise.
"""
Import
from utils.text_asset_tracker import save_and_track_text_content
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| db | Session | Yes | Database session |
| user_id | str | Yes | Clerk user ID |
| content | str | Yes | Text content to save |
| source_module | str | Yes | Source module (e.g. 'linkedin_writer') |
| title | str | Yes | Asset title |
| file_extension | str | No | .txt or .md (default .txt) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Optional[int] | Asset library ID, or None on failure |
| side effect | disk | File written to workspace/media/{module}_text/ |
| side effect | DB | Asset registered in content_asset_service |
| side effect | SIF | SIF indexing task triggered |
Usage Examples
Tracking a LinkedIn post
from utils.text_asset_tracker import save_and_track_text_content
asset_id = save_and_track_text_content(
db=db_session,
user_id="clerk_user_123",
content=linkedin_post_text,
source_module="linkedin_writer",
title="The future of open-source LLMs",
description="LinkedIn post grounded in 3 sources",
tags=["linkedin", "llm", "open-source"],
file_extension=".txt",
)
if asset_id:
print(f"Tracked as asset #{asset_id}")