By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Automating Content Tagging in Laravel Using OpenAI Embeddings and Cron Jobs | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > Automating Content Tagging in Laravel Using OpenAI Embeddings and Cron Jobs | HackerNoon
Computing

Automating Content Tagging in Laravel Using OpenAI Embeddings and Cron Jobs | HackerNoon

News Room
Last updated: 2025/12/15 at 7:19 AM
News Room Published 15 December 2025
Share
Automating Content Tagging in Laravel Using OpenAI Embeddings and Cron Jobs | HackerNoon
SHARE

It is tedious, inconsistent, and frequently incorrect to manually tag blog posts. With AI embeddings, Laravel can automatically determine the topic of a blog post and assign the appropriate tags without the need for human intervention.

This guide demonstrates how to create a complete Laravel AI auto-tagging system using:

  • The OpenAI Embeddings API
  • Laravel Jobs & Queues
  • Cron Scheduler
  • Tag → Vector Matching
  • Automatic Tag Assignment

This is one of the most useful AI enhancements for any Laravel-based CMS or blog system.

What We’re Constructing

You’ll construct:

  • Table of Tag Vector – The meaning of each tag (such as “PHP”, “Laravel”, “Security”, and “AI”) will be represented by an embedding vector created by AI.
  • A Generator for Post Embedding – We generate an embedding for the post content whenever a new post is saved.
  • A Matching Algorithm – The system determines which post embeddings are closest by comparing them with tag embeddings.
  • A Cron Job -The system automatically assigns AI-recommended tags every hour (or on any schedule).

This is ideal for:

  • Custom blogs made with Laravel
  • Headless CMS configurations
  • Tagging categories in e-commerce
  • Auto-classification of knowledge bases
  • Websites for documentation

Now let’s get started.

Step 1: Create Migration for Tag Embeddings

Run:

php artisan make:migration create_tag_embeddings_table

Migration:

    public function up()
    {
        Schema::create('tag_embeddings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tag_id')->unique();
            $table->json('embedding'); // store vector
            $table->timestamps();
        });
    }

Run:

php artisan migrate

Step 2: Generate Embeddings for Tags

Create a command:

php artisan make:command GenerateTagEmbeddings

Add logic:

`public function handle()         {             $tags = Tag::all();              foreach ($tags as $tag) {                 $vector = $this->embed($tag->name);                  TagEmbedding::updateOrCreate(                     ['tag_id' => $tag->id],                     ['embedding' => json_encode($vector)]                 );                  $this->info("Embedding created for tag: {$tag->name}");             }         }          private function embed($text)         {             $client = new GuzzleHttpClient();              $response = $client->post("https://api.openai.com/v1/embeddings", [                 "headers" => [                     "Authorization" => "Bearer " . env('OPENAI_API_KEY'),                     "Content-Type" => "application/json",                 ],                 "json" => [                     "model" => "text-embedding-3-large",                     "input" => $text                 ]             ]);              $data = json_decode($response->getBody(), true);              return $data['data'][0]['embedding'] ?? [];         }`

Run once:

php artisan generate:tag-embeddings

Now all tags have AI meaning vectors.

Step 3: Save Embeddings for Each Post

Add to your Post model observer or event.

`$post->embedding = $this->embed($post->content);         $post->save();`

Migration for posts:

`$table->json('embedding')->nullable();`

Step 4: Matching Algorithm (Post → Tags)

Create a helper class:

`class EmbeddingHelper         {             public static function cosineSimilarity($a, $b)             {                 $dot = array_sum(array_map(fn($i, $j) => $i * $j, $a, $b));                 $magnitudeA = sqrt(array_sum(array_map(fn($i) => $i * $i, $a)));                 $magnitudeB = sqrt(array_sum(array_map(fn($i) => $i * $i, $b)));                 return $dot / ($magnitudeA * $magnitudeB);             }         }`

Step 5: Assign Tags Automatically (Queue Job)

Create job:

php artisan make:job AutoTagPost

Job logic:

`public function handle()         {             $postEmbedding = json_decode($this->post->embedding, true);              $tags = TagEmbedding::with('tag')->get();              $scores = [];             foreach ($tags as $te) {                 $sim = EmbeddingHelper::cosineSimilarity(                     $postEmbedding,                     json_decode($te->embedding, true)                 );                 $scores[$te->tag->id] = $sim;             }              arsort($scores); // highest similarity first              $best = array_slice($scores, 0, 5, true); // top 5 matches              $this->post->tags()->sync(array_keys($best));         }`

Step 6: Cron Job to Process New Posts

Add to app/Console/Kernel.php:

`protected function schedule(Schedule $schedule)         {             $schedule->command('ai:autotag-posts')->hourly();         }`

Create command:

php artisan make:command AutoTagPosts

Command logic:

`public function handle()         {             $posts = Post::whereNull('tags_assigned_at')->get();              foreach ($posts as $post) {                 AutoTagPost::dispatch($post);                 $post->update(['tags_assigned_at' => now()]);             }         }`

Now, every hour, Laravel processes all new posts and assigns AI-selected tags.

Step 7: Test the Full Flow

  • Create tags in admin
  • Run: php artisan generate:tag-embeddings
  • Create a new blog post
  • Cron or queue runs
  • Post automatically gets AI-selected tags

Useful enhancements

  • Weight tags by frequency
  • Use title + excerpt, not full content
  • Add confidence scores to DB
  • Auto-create new tags using AI
  • Add a manual override UI
  • Cache embeddings for performance
  • Batch process 1,000+ posts

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Prediction: This Artificial Intelligence (AI) stock could beat Palantir in 2026. This is a good time to buy it by hand Prediction: This Artificial Intelligence (AI) stock could beat Palantir in 2026. This is a good time to buy it by hand
Next Article Newborn Not Sleeping? Try This Hidden iPhone Feature Newborn Not Sleeping? Try This Hidden iPhone Feature
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

GAC’s GOVY AirCab flying car enters airworthiness review, mass production eyed in 2026 · TechNode
GAC’s GOVY AirCab flying car enters airworthiness review, mass production eyed in 2026 · TechNode
Computing
How to get free Samsung Galaxy S25 phone at T-Mobile
How to get free Samsung Galaxy S25 phone at T-Mobile
News
Hackers Are Stealing Microsoft Account Passwords With This Trick – BGR
Hackers Are Stealing Microsoft Account Passwords With This Trick – BGR
News
VCs discuss why most consumer AI startups still lack staying power |  News
VCs discuss why most consumer AI startups still lack staying power | News
News

You Might also Like

GAC’s GOVY AirCab flying car enters airworthiness review, mass production eyed in 2026 · TechNode
Computing

GAC’s GOVY AirCab flying car enters airworthiness review, mass production eyed in 2026 · TechNode

1 Min Read
Vibe Coding is a Technical Debt Factory | HackerNoon
Computing

Vibe Coding is a Technical Debt Factory | HackerNoon

14 Min Read
DeFi Crypto Mutuum Finance (MUTM) Advances With V1 Launch in Focus Ahead of Q1 2026 | HackerNoon
Computing

DeFi Crypto Mutuum Finance (MUTM) Advances With V1 Launch in Focus Ahead of Q1 2026 | HackerNoon

8 Min Read
The Shadow of Ransomware on the Festive E-Shopping Season | HackerNoon
Computing

The Shadow of Ransomware on the Festive E-Shopping Season | HackerNoon

9 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?