Skip to content

feat: inner circle algorithm and interaction affinity ranking - #2708

Open
SuperJaba wants to merge 2 commits into
Datalux:developmentfrom
SuperJaba:feat/inner-circle-algorithm
Open

SuperJaba wants to merge 2 commits into
Datalux:developmentfrom
SuperJaba:feat/inner-circle-algorithm

Conversation

@SuperJaba

Copy link
Copy Markdown

Overview

When analyzing an Instagram target profile, raw follower or following lists fail to show who the target actually interacts with in real life.

This PR introduces an Inner Circle Algorithm that computes a multi-signal closeness/affinity score between the target and interacting accounts.

Key Changes

  1. Multi-Signal Affinity Engine (src/inner_circle.py):
    • Computes weighted closeness scores based on:
      • Mutual follow connections (target follows user AND user follows target) (+3.5)
      • In-photo usertags on target's posts (+3.0)
      • Comment frequency & interaction depth (+1.5)
      • Caption mentions (@username) (+2.0)
    • Tiers accounts into:
      • Core Confidant (Affinity score ≥ 8.0)
      • Close Friend (4.0 ≤ Affinity score < 8.0)
      • Frequent Contact (Affinity score < 4.0)
  2. Service Integration (src/osint_service.py):
    • Added get_inner_circle(limit=10, scan_posts=12) to OsintgramService.
    • Traverses target feed, comments, and followers/following to build affinity rankings.
  3. Web UI & CLI Tool Integration:
    • Registered get_inner_circle in src/web/tools.py.
    • Added command badge and dedicated visual card renderer in src/web/static/index.html displaying rank, profile avatar, tier pill, affinity star rating, and interaction badges (mutuals, tags, comments, mentions).
    • Documented command under Network in doc/web-ui.md (31 total commands).
  4. Tests:
    • Added tests/test_inner_circle.py covering scoring weights, tier categorization, target exclusion, service method, private profile guarding, and tool registration.

Verification

  • 178/178 tests passing (python -m pytest -q).
  • Flake8 0 errors (flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics).

@SuperJaba
SuperJaba force-pushed the feat/inner-circle-algorithm branch from d20d4dd to 65e7f4b Compare October 28, 2026 17:26
@Datalux

Datalux commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Correctness

  1. Mutual follows are computed from get_followers(limit=50) and get_followings(limit=50), i.e. the intersection of two 50-account samples. For most real accounts most mutuals will be missed, and is_following_target / is_followed_by_target will be False just because the account isn't in the sample. Please flag the result as partial when the sample is truncated (compare with the follower/following counts), or don't show those flags in that case.
  2. Comments are +1.5 each with no cap, so an account that comments six times (a bot, a fan, or a troll) reaches the "Core Confidant" tier. Please cap the contribution per post (e.g. count each post once, or use diminishing returns), and consider ignoring comments that are clearly hostile or spam.
  3. The mention regex @([A-Za-z0-9_.]+) captures the trailing period ("thanks @mario." gives mario.) and the domain of emails (a@b.com gives b.com). Please strip the trailing dots and skip matches preceded by a word character.
  4. The three except Exception: pass blocks hide failures (e.g. 429s) and the result looks complete. Please reuse the existing partial_warning mechanism, or return the error.

Naming and framing
"Core Confidant" and "Close Friend" claim a personal relationship that interaction counts can't support, and an account with only a mutual follow (3.5, no interaction) ends up as "Frequent Contact". Please use neutral labels (e.g. High / Medium / Low interaction) and add a short disclaimer in the UI and in doc/web-ui.md: "interaction indicator, not evidence of a relationship".

Cost
Each run makes about 16 requests (feed, one comments call per post, followers, following), and scan_posts has no upper limit, so the AI tool could ask for 1000 posts. Please cap scan_posts (e.g. 30) server-side, as in #2706.

Tests
Please add tests for repeated comments from one account, the mention with a trailing period, a failing sub-fetch, and a truncated follower sample.

Thanks!

@SuperJaba
SuperJaba force-pushed the feat/inner-circle-algorithm branch from 77d09db to f658994 Compare October 30, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants