{"id":35068771,"url":"https://github.com/beclab/r4","last_synced_at":"2026-05-20T17:31:54.929Z","repository":{"id":236722563,"uuid":"793011887","full_name":"beclab/r4","owner":"beclab","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-19T01:17:12.000Z","size":607,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-19T09:14:20.106Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beclab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-04-28T07:11:14.000Z","updated_at":"2025-04-19T01:16:14.000Z","dependencies_parsed_at":"2024-08-26T13:06:10.211Z","dependency_job_id":"111a6ca3-d1c3-4fc7-8d90-501c97fa532e","html_url":"https://github.com/beclab/r4","commit_stats":null,"previous_names":["beclab/r4"],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/beclab/r4","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beclab%2Fr4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beclab%2Fr4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beclab%2Fr4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beclab%2Fr4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beclab","download_url":"https://codeload.github.com/beclab/r4/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beclab%2Fr4/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33269228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-20T15:12:43.734Z","status":"ssl_error","status_checked_at":"2026-05-20T15:12:42.300Z","response_time":356,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-27T11:41:13.127Z","updated_at":"2026-05-20T17:31:54.920Z","avatar_url":"https://github.com/beclab.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# R4\n![R4 Droid](https://premium-storefronts.s3.amazonaws.com/storefronts/r4-p17s-store/assets/bg_home_banner.jpeg)\n\n**R4** is a family of decentralized recommendation algorithms offered by Terminus. It provides recommendations for various topics including world news, sports headlines, business reports, and so on.\n\nThe name R4 is inspired by Obi-Wan’s intelligent and trustworthy droid from the Star Wars series.\n\n\u003e He was a cunning warrior and a good friend \u003cbr\u003e\n\u003e \\- Obi-Wan Kenobi\n\n## Key Features\n**Security and Privacy First**\u003cbr\u003e\nR4 operates in an offline sandbox on Terminus Edge, ensuring no data is sent to third-party servers. All user's personal data will be encrypted and stored locally.\n\n**Personalized Content Curation**\u003cbr\u003e\nR4 uses user behavioral data, such as reading, liking, and bookmarking, to create a dynamic user profile. It automatically updates recommendations in response to changes in user behavior and global trends.\n\n**Lightweight Design**\u003cbr\u003e\nR4 employs a classical recommendation process to achieve better results with minimal resources. It includes crucial steps like recall, pre-rank, and rank. It also utilizes the embedding results from content providers to conserve computational resources.\n\n## Recommendation Pipline in General\nR4 employs a classic recommendation process, illustrated as follows:\n```\nrecall-\u003eprerank-\u003ecrawler-\u003eextractor-\u003erank\n```\n- **Recall** retrieves the packet from JuiceFS and removes irrelevant content, leaving approximately 10,000 articles for further sorting. The recall result is then stored in NFS.\n- **Prerank** get the recall results from NFS, sorts the retrieved content, and stores prerank results in MongoDB using `knowledge`.\n\n- **Crawler** is a system process. It finds entries in the prerank result that haven't been crawled yet, then uses the URL to fetch the raw content and save it.\n\n- **Extractor** eliminates clutter on a webpage, such as buttons, ads, background images, and videos, from the raw content fetched by the Crawler. It then saves this cleaned data to the `knowledge`.\n\n- **Rank** fine-tunes the order of content based on the extracted full-text, suggesting the content that best aligns with the user's current interests.\n\nThere will be an additional process to ensure the ranking model and user-embedding module are updated promptly.\n\n## Main Environment Variables\n| Parameter                            | describe                                                   |\n|--------------------------------------|------------------------------------------------------------|\n| NFS_ROOT_DIRECTORY                   | nfs directory，save recall and prerank results             |\n| JUICEFS_ROOT_DIRECTOR                | juicefs directory，save feed and entry datas from cloud    |\n| TERMINUS_RECOMMEND_SOURCE_NAME       | source name,identify the algorithm                         |\n| KNOWLEDGE_BASE_API_URL               | knowledge api address                                      |\n| SYNC_PROVIDER                        | cloud data provider                                        |\n| SYNC_FEED_NAME                       | cloud data feed name                                       |\n| SYNC_MODEL_NAME                      | cloud entry data model name                                |\n\nThe system module sync retrieves content index packets from the cloud. The data sources are configured in the Market, for example.\n```\noptions:\n  syncProvider:\n  - provider: bytetrade\n    feedName: news\n    feedProvider: \n      url: https://recommend-provider-prd.bttcdn.com/api/provider/feeds?name=feed_base\n    entryProvider: \n      syncDate: 15\n      url: https://recommend-provider-prd.bttcdn.com/api/provider/entries?language=zh-cn\u0026model_name=bert_v2\n  - provider: bytetrade\n    feedName: tech\n    feedProvider: \n      url: https://recommend-provider-prd.bttcdn.com/api/provider/feeds?name=feed_base\n    entryProvider: \n      syncDate: 15\n      url: https://recommend-provider-prd.bttcdn.com/api/provider/entries?language=zh-cn\u0026model_name=bert_v2\n```\n\nIn this configuration, the algorithm utilizes two data sources: `news` and `tech`. These packets are stored in JuiceFS, in the following directories:\n- Feed data: JUICEFS_ROOT_DIRECTORY/feed/bytetrade/news\n- Entry data: JUICEFS_ROOT_DIRECTORY/entry/bytetrade/news/{model_name}\n\n## Algorithm Workflows in Argo  \n```mermaid\ngraph TD\n  A[algorithm]--\u003eB(recall);\n  A--\u003eC(extractor);\n  A--\u003eD(train);\n  A--\u003eE(embedding);\n  B--\u003eF(prerank);\n  C--\u003eG(rank);\n  D--\u003eH(rank);\n```\n- The recall and prerank workflow generates prerank results and is scheduled to run every 10 minutes.\n- The extractor and rank workflow produces rank results.\n  - If the `last_extractor_time` is later than the `last_crawler_time`, the extractor task will not be executed.\n  - If the `last_rank_time` is later than the `last_extractor_time`, the rank task will not be executed.\n- The train workflow creates a new ranking model, and then carries out the ranking task with the latest model to produce ranking results.\n- The embedding workflow updates the user's embedding value.\n\n# Algorithm Architecture\n- [prerank-stages](#prerank-stages)\n- [train-rank](#train-rank)\n- [user-embedding](#user-embedding)\n\n\n## Prerank Stages\nThis part of the code includes recall, prerank and extractor modules. Details are documented [here](prerank-stages/README.md)\n\n### Directory structure\n```\nsystem workflow\n|-- api                  # knowledge api     \n|-- common               \n|-- config               # algorithm config \n|-- extractor            # extractor module\n|-- model                #\n|-- prerank              # prerank module\n|-- protobuf_entity      # protobuf data format   \n|-- recall               # recall module\n```\n\n### recall\n```\n1. Get parameters user_embedding ,last_recall_time from knowledge.\n2. Get the incremental entry data in juicefs and last recall result in nfs.\n3. Generate recall result and save the data in nfs.\n4. Set last_recall_time through knowledge.\n```\n\n### prerank\n```\n1. Get parameters user_embedding   from knowledge.\n2. Get recall result from nfs.\n3. Generate prerank result and save data through knowledge.\n    - Get the data that this algorithm has produced.\n    - If the new data does not exist before, add recommended data through knowledge.\n    - If the previous data is not in the current prerank result, delete the data through knowledge.\n```\n\n### extractor\n```\n1. Get the entry list(crawler=true、extract=false) through knowledge.\n2. For each entry, parse the text content based on raw content.\n3. Batch update the entry data through knowledge.\n```\n\n## train-rank\nThis part of the code is about the rank operation of the process and the training of the rank model.\n\nMore details [here](train-rank/README.md)\n\n\n## user-embedding\nThis part is about the calculation of userembedding. The general principle involves calculating a temporary user vector based on the articles a user has read recently. This temporary user vector is then added to the existing user vector to generate a new user vector.\n\nMore details [here](user-embedding/README.md)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeclab%2Fr4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeclab%2Fr4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeclab%2Fr4/lists"}