Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:ALwrity ALwrity ResearchService research

From Leeroopedia
Knowledge Sources
Domains Blog_Writer, Research, SEO
Last Updated 2026-10-24 00:00 GMT

Overview

Concrete tool for AI-orchestrated research and strategy generation using Exa neural search, provided by the ALwrity blog writer subsystem.

Description

The ResearchService.research method is stage 1 of the blog writer pipeline. It takes a BlogResearchRequest (keywords, topic, industry, persona, research_mode, config) and a Clerk user ID, validates subscription limits via PricingService, then routes to the ExaResearchProvider to perform a neural search. The results are filtered and shaped by internal helpers (KeywordAnalyzer, CompetitorAnalyzer, ContentAngleGenerator, ResearchDataFilter) into a BlogResearchResponse containing sources, keyword analysis, competitor analysis, and suggested content angles. Results are cached by the research_cache so identical keyword/industry/audience combinations return cached results without a new Exa call.

Currently Exa is the only supported provider; requests for other providers raise an error during testing.

Usage

Import this service when:

  • The blog writer pipeline needs research sources and a content strategy for a keyword set.
  • A returning user with the same keywords should hit the research cache.
  • Subscription pre-flight validation must gate expensive Exa calls.

Code Reference

Source Location

  • Repository: ALwrity
  • File: backend/services/blog_writer/research/research_service.py (L47-394)

Signature

class ResearchService:
    def __init__(self):
        self.keyword_analyzer = KeywordAnalyzer()
        self.competitor_analyzer = CompetitorAnalyzer()
        self.content_angle_generator = ContentAngleGenerator()
        self.data_filter = ResearchDataFilter()

    async def research(
        self,
        request: BlogResearchRequest,
        user_id: str,
    ) -> BlogResearchResponse:
        """
        Stage 1: Research & Strategy (AI Orchestration).
        Uses Exa neural search as the primary research provider.

        Args:
            request: BlogResearchRequest with keywords, topic, industry, persona,
                     research_mode, config.
            user_id: Clerk user ID for subscription validation.

        Returns:
            BlogResearchResponse with sources, keyword_analysis,
            competitor_analysis, suggested_angles, grounding_metadata.

        Raises:
            HTTPException: On subscription limits or DB unavailability.
            ValueError: If user_id is missing or non-Exa provider requested.
        """

Import

from services.blog_writer.research.research_service import ResearchService

I/O Contract

Inputs

Name Type Required Description
request BlogResearchRequest Yes keywords, topic, industry, persona, research_mode, config
user_id str Yes Clerk user ID for subscription/provider routing

Outputs

Name Type Description
return BlogResearchResponse sources, keyword_analysis, competitor_analysis, suggested_angles, grounding_metadata
side effect cache Result cached by keywords/industry/audience key

Usage Examples

Running research for a keyword set

from services.blog_writer.research.research_service import ResearchService
from models.blog_models import BlogResearchRequest, ResearchMode, ResearchConfig, ResearchProvider

service = ResearchService()
request = BlogResearchRequest(
    keywords=["fine-tuning llms", "qlora"],
    topic="A guide to fine-tuning open LLMs",
    industry="AI/ML",
    research_mode=ResearchMode.BASIC,
    config=ResearchConfig(mode=ResearchMode.BASIC, provider=ResearchProvider.EXA),
)

response = await service.research(request, user_id="clerk_user_123")
print(f"Found {len(response.sources)} sources")
print(response.suggested_angles)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment