{"slug": "how-we-re-using-gemini-embeddings-to-build-a-smarter-community-driven-feed-on", "title": "How we're using Gemini Embeddings to build a smarter, community-driven feed on DEV", "summary": "The DEV platform is implementing a new feed algorithm that combines traditional community signals (like follows and reactions) with Google's Gemini Embeddings 2 model and PostgreSQL's pgvector extension to surface high-quality, conceptually relevant content. The system creates dynamic \"interest embeddings\" for each user based on their interactions, then calculates cosine similarity scores between those interests and article embeddings to rank posts, mixing semantic relevance with standard social signals and time decay. This approach allows the feed to balance personalized content discovery with community trends while future-proofing the infrastructure for multimodal content like images, audio, and video.", "body_md": "Big improvements incoming 👋\n\nFinding the right balance for a feed algorithm is historically really hard. If you optimize purely for clicks and comments, you end up with a clickbait echo chamber. But if you just sort by recency, it's a firehose where great discussions disappear in hours.\n\nWe've wrestled with this tension at DEV for a long time. We want a feed that feels alive, but actually surfaces high-quality, intellectually stimulating stuff.\n\nSo, we're trying something new. We are combining standard community signals—like who you follow and what you react to—with [Gemini Embeddings 2](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/embedding-2) and `pgvector`\n\n.\n\nHere is a look under the hood at how we are putting this together.\n\n## 1. Keeping things flexible and auditable\n\nInstead of duct-taping API calls all over the codebase, we built a flexible foundation using wrapper classes, mostly centered around `Ai::Base`\n\nand `Ai::Embedding`\n\n.\n\nWhen a service needs the API, it just passes `wrapper: self`\n\nto the client. This lets `Ai::Base`\n\nlook at the calling object, grab its class name, and check its `VERSION`\n\n.\n\n```\nAi::Base.new(wrapper: self)\n```\n\nThis pattern gives us a really clean audit trail via our `AiAudit`\n\nmodel. Every single time we generate a vector or analyze a trend, we automatically log the model used, the caller's class, payloads, latency, and token counts.\n\nIt makes debugging and tracking costs so much easier, without muddying up our core business logic.\n\n## 2. A more personalized feed\n\nOur main feed is powered by `FeedConfig`\n\n. It compiles custom SQL to score and rank articles for you.\n\nHistorically, this was all hardcoded math based on things like tags and whether you follow the author. Now, we've introduced a semantic feedback loop.\n\nAs you interact with the platform, we compile a dynamic `interest_embedding`\n\nthat represents what you actually care about. We use the `pgvector`\n\nextension in PostgreSQL to inject your interests directly into the SQL query:\n\n```\n(\n  CASE\n    WHEN articles.semantic_embedding IS NOT NULL\n      AND articles.published_at >= :published_since\n    THEN (1 - (articles.semantic_embedding <=> :interest_embedding)) * :semantic_similarity_weight\n    ELSE 0\n  END\n)\n```\n\nBy using `1 - (embedding <=> user_interest)`\n\n, we get a cosine similarity score. We scale that up and mix it in with standard social signals (like who you follow), post quality, and time decay.\n\nThis means a highly relevant post can rise to the top of your feed, but so can a globally trending post from a community member you love. It’s all about balance.\n\n## 3. What the heck is an embedding anyway? (And why v2 matters)\n\nIf you're new to the concept, an embedding is basically taking a piece of content—like an article text—and turning it into a long string of numbers (a vector). These numbers map the content into a \"semantic space.\" If two posts are talking about the exact same conceptual ideas, their numbers will look very similar mathematically, even if they use completely different wording.\n\nWe've upgraded this pipeline to use Google's newly released **Gemini Embeddings 2** model.\n\nA standard text embedding model only looks at words. But Gemini Embeddings 2 compiles into massive 3,072-dimensional vectors and maps everything into a single, unified semantic space.\n\n### Future-proofing for a multi-modal DEV\n\nThe coolest part about moving to Embeddings 2 is that it isn't just restricted to text. It natively accepts multimodal inputs—meaning text, code, images, audio, and video.\n\nRight now, we're using it to analyze written DEV posts. But because the underlying math maps everything into the exact same vector space, we are completely future-proofing our infrastructure. As the DEV platform evolves, we can easily feed images, podcast audio, or video posts into the exact same database architecture[.\n\nA user's `interest_embedding`\n\nwill be able to effortlessly surface an open-source video tutorial or a technical podcast episode based entirely on conceptual relevance, without us needing to rewrite our feed logic from scratch.\n\n## 4. Catching nuanced trends 📈\n\nTags are great for high-level sorting, but they miss the highly specific, timely conversations. If Ruby 3.4 drops, a `#ruby`\n\ntag search won't distinguish between a \"Hello World\" tutorial and a deep debate about the new parser.\n\nTo fix this, we are in the process of building a clustering service powered by `TrendDetector`\n\n.\n\nEvery 6 hours, a background job runs a Leader Clustering algorithm in pure Ruby:\n\n-\n**Quality first:** We only look at recent articles scoring at least 15 points above our homepage minimum. -\n**Clustering:** We measure the cosine distance between articles. If a post is close enough (`0.15`\n\nor less) to an existing cluster, it joins it. If not, it starts a new one. -\n**Labeling:** Once a cluster hits 10 or more articles, we ask the Gemini API to label the trend and summarize the core debate.\n\nWe store all of this in `TrendMembership`\n\n, which lets us sort articles in the UI based on how close they are to the core topic.\n\nAll of this can be tracked via our open source codebase Forem:\n\n# Forem 🌱\n\n**For Empowering Community**\n\nWelcome to the [Forem](https://forem.com) codebase, the platform that powers\n[dev.to](https://dev.to). We are so excited to have you. With your help, we can\nbuild out Forem’s usability, scalability, and stability to better serve our\ncommunities.\n\n## What is Forem?\n\nForem is open source software for building communities. Communities for your\npeers, customers, fanbases, families, friends, and any other time and space\nwhere people need to come together to be part of a collective\n[See our announcement post](https://dev.to/devteam/for-empowering-community-2k6h)\nfor a high-level overview of what Forem is.\n\n[dev.to](https://dev.to) (or just DEV) is hosted by Forem. It is a community of\nsoftware developers who write articles, take part in discussions, and build\ntheir professional profiles. We value supportive and constructive dialogue in\nthe pursuit of great code and career growth for all members. The ecosystem spans\nfrom beginner to advanced developers, and all are welcome to find their place…\n\n## 5. Putting the community first ❤️\n\nHuman curation, both from the broader community and our editorial perspective, is still the backbone of the system.\n\nWe are using Gemini Embeddings to amplify what the community is already doing. It’s about mixing the raw utility of vector search with the human spirit of developer-voted scores and relationships.\n\nWe want DEV to be the best place on the internet to share code and talk about software. We think this is a big step in that direction.\n\nWhat do you think? Let me know in the comments.\n\nHappy coding!", "url": "https://wpnews.pro/news/how-we-re-using-gemini-embeddings-to-build-a-smarter-community-driven-feed-on", "canonical_source": "https://dev.to/devteam/how-were-using-gemini-embeddings-to-build-a-smarter-community-driven-feed-on-dev-1b9f", "published_at": "2026-05-22 16:27:19+00:00", "updated_at": "2026-05-22 17:08:43.210190+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "large-language-models", "developer-tools", "data"], "entities": ["Gemini Embeddings", "pgvector", "DEV", "Ai::Base", "Ai::Embedding", "FeedConfig", "AiAudit"], "alternates": {"html": "https://wpnews.pro/news/how-we-re-using-gemini-embeddings-to-build-a-smarter-community-driven-feed-on", "markdown": "https://wpnews.pro/news/how-we-re-using-gemini-embeddings-to-build-a-smarter-community-driven-feed-on.md", "text": "https://wpnews.pro/news/how-we-re-using-gemini-embeddings-to-build-a-smarter-community-driven-feed-on.txt", "jsonld": "https://wpnews.pro/news/how-we-re-using-gemini-embeddings-to-build-a-smarter-community-driven-feed-on.jsonld"}}