{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Cristian Leo",
  "title_listed": "The Algorithm That Made Google Google",
  "keywords": "",
  "domain": "大模型算法",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://towardsdatascience.com/the-algorithm-that-made-google-google-3bbc2cfa8815/",
  "publish_date": "2024-12-18",
  "corpus_stage": "",
  "notes": "",
  "id": "3102ef8859a3",
  "collected_at": "2026-10-02T05:56:21",
  "title": "The Algorithm That Made Google Google | Towards Data Science",
  "body_markdown": "![Revisit consent button](../images/body-df29beacd7496220cc94.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](../images/body-2159bb67f3de8ad870eb.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\n# The Algorithm That Made Google Google\nHow PageRank transformed how we searched the internet, and why it's still playing an important role in LLMs with Graph RAG.\n[Cristian Leo](https://towardsdatascience.com/author/cristianleo120/)\nDecember 18, 202417 min read\n![Image generated by DALL-E](../images/000.jpeg)\nImage generated by DALL-E\nIn the late 1990s, two Stanford University graduate students, Larry Page and Sergey Brin, were working on their PhD research when they came across an interesting idea.\nLarry was particularly fascinated by the way web pages linked to one another. He saw the internet as a vast network of citations, similar to how academic papers reference each other. This sparked an idea: **what if a web page's importance could be measured by how many other pages linked to it?** But not just that - **what if the importance of those linking pages also mattered?**\nIntrigued by that idea, Larry started building an algorithm that would later be named \"PageRank\" (a clever play on his last name). The algorithm treated each link to a webpage as a vote of confidence, but with a twist - votes from more important pages carried more weight.\nSergey Brin, interested in Larry's concept, joined him. Together, they worked from their dorm rooms, building a search engine that would use this ranking system. At first, they called their project \"BackRub\" due to its analysis of backward links.\nAs their project grew, they realized they had something special on their hands. Their search engine was producing significantly better results than existing search engines of the time. In 1998, they decided to take a leave of absence from Stanford to focus on their project full-time.\nThey renamed their search engine \"Google\" - again a play, this time on the mathematical term \"googol\" (a number represented by 1 followed by 100 zeros) - reflecting their ambition to organize the vast amount of information on the web. With some initial funding from investors, including a $100,000 check written in their garage office, Google was officially born. The rest is history.\nLearn this step by step with the interactive [AI Engineer](https://roadmap.sh/ai-engineer) and [Machine Learning](https://roadmap.sh/machine-learning) roadmaps.\n## Breaking down PageRank\nNow, let's imagine we have 4 high school students: Amy, Bob, Charlie, and Diana. They are trying to decide who is more and less \"cool\", and how \"cool\" everyone is depends on how much support they get from the others. In particular, they have a pool of 100 \"cool\" points that is distributed to each student, hence 25 points each. Then, each student needs to give all their points to one or more students.\nLet's say:\n  * Amy vouches for Bob\n  * Bob vouches for Amy\n  * Charlie vouches for Amy and Diana\n  * Diana vouches for everyone\n\n\nAfter one round:\n  * Amy gets points from Bob (25) and half of Charlie's points (12.5) totaling 37.5 points\n  * Bob gets points from Amy (25) totaling 25 points\n  * Diana gets half of Charlie's points (12.5) totaling 12.5 points\n\n\nThen, the points get redistributed again and again until they stabilize. With this mechanism, the more popular you are, the more valuable your vouch is.\nThis is basically how PageRank works, just with websites instead of students and links instead of vouchers.\n### The Math Behind PageRank\nAt its heart, PageRank is based on a simple, but very powerful idea: the importance of a webpage can be determined by the quantity and quality of links pointing to it. This concept can be broken down into several key principles:\n  1. Every link to a page is a vote of confidence for that page.\n  2. The importance of the page casting the vote matters.\n  3. The more links a page casts, the less weight each link carries.\n\n\nFirst, we need to understand the concept of the \"random surfer.\" Imagine you're mindlessly clicking links on the internet (we've all been there, right?). You start on a random page, click a link, then another, and another. Occasionally, you get bored and just type in a new web address. This aimless journey is what we call the \"random surfer model.\"\nThe PageRank of a webpage is basically the probability that this random surfer will end up on that page after clicking around for a really, really long time (theoretically, an infinite amount of time, but let's not get too philosophical here).\nNow, here's where it gets interesting. The PageRank formula looks like this:\n![PageRank formula - Image by Author](../images/011.png)\nPageRank formula - Image by Author\nWhere:\n  * **PR(A)** is the PageRank of page A\n  * **d** is the damping factor (typically 0.85), which represents the probability that the random surfer will continue clicking links rather than jumping to a random page.\n  * **N** is the total number of pages in the network\n  * **PR(T_i)** is the PageRank of pages **T_i** which links to page A\n  * **C(T_i)** is the number of outbound links from page T_i\n  * **n** is the number of pages that link to page A\n\n\nNow, let's look at the two parts of this formula:\n![Left component in PageRank Formula - Image by Author](../images/002.png)\nLeft component in PageRank Formula - Image by Author\nThis is the probability that our random surfer gets bored and jumps directly to page A. It's like rolling a die with N sides (where N is the number of pages on the internet) and landing on page A.\n![Right component in PageRank Formula - Image by Author](../images/003.png)\nRight component in PageRank Formula - Image by Author\nThis is the meaty part. It represents the probability of arriving at page A by following links. Each term in this sum is the PageRank of a page linking to A, divided by the number of links on that page.\nPageRank is also recursive, which means that page A depends on the PageRank of the pages linking to it, which in turn depend on the pages linking to them, and so on. It's like a never-ending chain of popularity contests!\nSo how do we actually calculate this? We use an iterative process:\n  1. Start by giving every page an equal PageRank (let's say 1/N).\n  2. Use our formula to calculate new PageRank values for each page.\n  3. Repeat step 2 until the values stop changing much between iterations.\n\n\nNow, you might be thinking, \"Wait a minute, what about pages with no outgoing links? Or pages that only link to each other?\" Great questions! These are what we call \"dangling nodes\" and \"rank sinks,\" and they can cause problems for our algorithm.\nFor dangling nodes (pages with no outgoing links), we usually pretend they link to all other pages equally. For rank sinks (groups of pages that only link to each other), the random jump factor (1-d) helps prevent them from hoarding all the PageRank.\nOk that seems easy when dealing with 4 pages, but how can we scale it to the whole internet? Here, we use a few tricks to make it manageable:\n  1. **Sparse Matrix Representation** : Most pages only link to a few others, so we can save a lot of memory by only storing the non-zero elements of our link matrix.\n  2. **Distributed Computing** : We can split up the calculation across many computers, each working on a different part of the web.\n  3. **Approximation Methods** : For really huge networks, we might use algorithms that give us a good estimate of PageRank without calculating it exactly for every single page.\n\n\nAnd remember, the web is constantly changing. New pages are created, old ones disappear, links are added and removed. So Google (and other search engines) need to keep updating their PageRank calculations all the time.\n### Practical example\nLet's start with a small web of just four pages to illustrate how PageRank actually works in practice. Imagine we have pages A, B, C, and D with the following link structure:\n  * Page A links to B and C\n  * Page B links to C and D\n  * Page C links to A\n  * Page D links to C\n\n\n![4 pages example visualized in a Knowledge Graph - Image by Author](../images/004.png)\n4 pages example visualized in a Knowledge Graph - Image by Author\nNow, let's calculate the PageRank for these pages step by step. We'll use a damping factor (d) of 0.85, which is the typical value used in practice.\n**Step 1: Initialize PageRank** We start by giving each page an equal PageRank. Since we have 4 pages, each page starts with a PageRank of 1/4 = 0.25.\n![Equal probabilities among the 4 pages - Image by Author](../images/005.png)\nEqual probabilities among the 4 pages - Image by Author\n**Step 2: Calculate new PageRank values** Now we'll use our PageRank formula for each page. Remember, the formula is:\n![Calculate new page rank values using PageRank formula - Image by Author](../images/011.png)\nCalculate new page rank values using PageRank formula - Image by Author\nWhere N is the total number of pages (4 in our case), Y are the pages linking to X, and C(Y) is the number of outbound links from Y.\n![First iteration of calculation for 4 pages - Image by Author](../images/007.png)\nFirst iteration of calculation for 4 pages - Image by Author\n**Step 3: Iterate** Now we use these new PageRank values and repeat the calculation. Let's do one more iteration:\n![Second iteration of calculation for 4 pages - Image by Author](../images/008.png)\nSecond iteration of calculation for 4 pages - Image by Author\nWe would continue this process until the values converge (change very little between iterations). Indeed, the PageRank algorithm is guaranteed to converge because of the properties of the Google matrix (the matrix representing the web's link structure plus the damping factor). This matrix is stochastic (each column sums to 1) and irreducible (there's a path between any two pages), which ensures convergence to a unique solution.\n## 4: From Math to Code\nNow, it's time to switch from theory to practice with a Python implementation of PageRank on a Knowledge Graph. Here, we will:\n  1. Connect to a Neo4j graph database.\n  2. Create a small sample graph structure to understand the basics.\n  3. Crawl a subset of Wikipedia pages to build a larger, more realistic network of links.\n  4. Load this network into Neo4j, creating nodes for pages and relationships for links.\n  5. Implement PageRank in Python from scratch and run it on the graph data stored in Neo4j.\n\n\nYou can find all the code we will cover in this section on this Jupyter Notebook:\n> [**rag-knowledge-graph/pagerank/demo.ipynb at main · cristianleoo/rag-knowledge-graph**](https://github.com/cristianleoo/rag-knowledge-graph/blob/main/pagerank/demo.ipynb)\n### Setting up the Neo4j Connection\nFirst, we need to set up a connection to our Neo4j database. Neo4j is a graph database that stores data in nodes (think webpages) and relationships (think hyperlinks). Connecting to it allows us to store our crawled data and run queries to build the link structure we need for PageRank. If you read my previous Graph RAG article, you would already know how to set it up, so just jump straight to the code. If not, let's first go over the Neo4j installation process. We will be using Neo4j just because it provides an easy installation and free option for local hosting (I don't have any sort of affiliation with it).\nTo install Neo4j simply visit the [Neo4j Desktop Download Page](https://neo4j.com/download/) and click Download. Open **Neo4j Desktop** after installation. Sign in or create a **Neo4j account** (required to activate the software).\nOnce logged in, create a **New Project** :\n  * Click on the `**+**`button in the top-left corner.\n  * Name your project (e.g., \"PageRank\").\n\n\nInside your project, click on `**Add Database**`. Select**Local DBMS** and click **Create a Local Graph**.\nConfigure your database:\n  * **Name** : Enter a name (e.g., `neo4j`).\n  * **Password** : Set a password (e.g., `pagerank`). Remember this password for later.\n\n\nClick **Create** to initialize the database.\nNow, let's move on to the code:\npython\n\n```\nfrom neo4j import GraphDatabase\nimport json\nimport wikipediaapi\nimport random\nfrom tqdm import tqdm\nfrom collections import deque\nimport numpy as np\n```\n\nWe import the `GraphDatabase` class to connect to a Neo4j database and run queries against it. This will be our main class to handle operation against our Knowledge Graph.\nNext, we import a series of Python libraries: `json` for reading and writing data in JSON format, `wikipediaapi` for accessing Wikipedia pages, `random` for random selection of links, `tqdm` for progress bars, `deque` (a double-ended queue) for efficiently handling lists we will treat like queues, and `numpy` for mathematical operations.\npython\n\n```\n# Connect to Neo4j\nuri = \"bolt://localhost:7687\"  # Change this to your Neo4j URI\nusername = \"neo4j\"  # Change this to your Neo4j username\npassword = \"pagerank\"  # Change this to your Neo4j password\n\ndriver = GraphDatabase.driver(uri, auth=(username, password))\n```\n\nLet's define the connection for the Neo4j instance. In a production environment, you'd make sure these credentials are secure, but for our demonstration, we'll keep it simple.\nNext, we create a `driver` object that lets us open sessions to the database and run queries. Think of this as \"plugging in\" your Python code to the Neo4j database engine.\n### Crawling Wikipedia\nFor our example, we will crawl 100 pages from Wikipedia, starting from a single article. We'll follow links to other articles, pick a few at random, and build a larger link network. This mimics the random surfer model we discussed, except we're not just simulating a random surfer's journey - we're actually collecting the links themselves.\npython\n\n```\ndef crawl_wiki_network(start_title, max_articles=100, max_links_per_article=5):\n    # Initialize Wikipedia API\n    wiki = wikipediaapi.Wikipedia(\n        'RAG Knowledge Graph (cristianleonardi@gmail.com)',\n        'en'\n    )\n```\n\nThis `crawl_wiki_network` **** function starts at a given Wikipedia article and crawls through linked pages. Inside it, we create a Wikipedia API object. The arguments identify our application and language (English in this case).\npython\n\n```\n    # Track visited pages and links\n    visited_pages = set()\n    links_data = []\n    pages_to_visit = deque([start_title])\n```\n\nLet's initialize `visited_pages = set()` to keep track of which pages we've already processed so we don't repeat work. Next, `links_data = []` will store information about the links we discover: from which page the link came, to which page it goes, and some context.\nAlso, we start with a queue that initially contains just one page: the page we start from (e.g., \"Artificial intelligence\"). We'll pull pages off this queue and explore them.\npython\n\n```\n    with tqdm(total=max_articles) as pbar:\n        while pages_to_visit and len(visited_pages) < max_articles:\n            current_title = pages_to_visit.popleft()\n\n            if current_title in visited_pages:\n                continue\n```\n\nWe use `tqdm` for a nice progress bar so we know how many articles we've processed out of `max_articles`. We continue crawling as long as there are pages to visit and we haven't hit our limit of articles via the `while` loop.\n`popleft()` removes the next page title from our queue, and in case we've already seen this page, skip it to avoid loops.\npython\n\n```\n            page = wiki.page(current_title)\n            if not page.exists():\n                continue\n```\n\nNext, we fetch the page from Wikipedia, and in case of broken links we skip the page.\npython\n\n```\n            visited_pages.add(current_title)\n            pbar.update(1)\n```\n\nOnce, we visit the new page, we add it to the `visited_pages` set, and update our progress bar, showing that we've successfully processed another article.\npython\n\n```\n            # Get all links from the page\n            page_links = list(page.links.items())\n\n            # Randomly select a subset of links\n            selected_links = random.sample(\n                page_links, \n                min(max_links_per_article, len(page_links))\n            )\n```\n\nNext, we get all the links found on the current page, and pick a few links at random, up to `max_links_per_article`. This mimics the idea that our random surfer won't follow every single link, just a handful.\npython\n\n```\n            # Process selected links\n            for link_title, link_page in selected_links:\n                if link_page.exists():\n                    # Add link to queue for future processing\n                    pages_to_visit.append(link_title)\n\n                    # Get the first paragraph as context\n                    context = link_page.summary.split('n')[0] if link_page.summary else \"\"\n\n                    links_data.append({\n                        \"from\": current_title,\n                        \"to\": link_title,\n                        \"context\": context\n                    })\n```\n\nNext, we iterate over each chosen link, and for each valid link (skipping broken as before):\n  * We add it to our queue, so we can explore it in a future iteration.\n  * Extract a bit of context (like a snippet of text) from the linked page, giving us more info if needed.\n  * Store the \"from → to\" link in `links_data`. This data will later help us build a graph in Neo4j and eventually run PageRank.\n\n\npython\n\n```\nreturn links_data\n```\n\nAfter we've reached our maximum number of articles or run out of links, we return all the link data we collected.\n### Saving the Crawled Network\nNow we have a crawler that returns link data. Let's save this data as a JSON file for future use.\npython\n\n```\ndef save_network(start_title, output_file=\"wikipedia_network.json\"):\n    links_data = crawl_wiki_network(start_title)\n    if links_data:\n        with open(output_file, 'w', encoding='utf-8') as f:\n            json.dump(links_data, f, indent=2, ensure_ascii=False)\n        print(f\"Saved {len(links_data)} links to {output_file}\")\n```\n\nThis function runs the crawler, takes the returned `links_data`, and writes it out to a JSON file.\npython\n\n```\n# You can start with any article\nstart_article = \"Artificial intelligence\"\nsave_network(start_article)\n```\n\nWe choose a starting point for our crawl - here it's \"Artificial intelligence.\" We could pick any article to begin the chain, and run the whole process and save the results.\n_(As the crawler runs, we'll see a progress bar. Eventually, it prints something like: \"Saved 495 links to wikipedia _network.json\".)_\n### Loading the Network into Neo4j\nNow that we have a JSON file full of link data, let's load it into Neo4j so we can store and query the network there. This will let us handle larger datasets more easily and perform efficient lookups when we implement PageRank.\npython\n\n```\ndef load_wiki_network(file_path=\"wikipedia_network.json\"):\n    # Read the JSON file\n    with open(file_path, 'r', encoding='utf-8') as f:\n        links_data = json.load(f)\n\n    # Connect to Neo4j and load the data\n    with driver.session() as session:\n        # Create unique constraints if they don't exist\n        session.run(\"CREATE CONSTRAINT page_name IF NOT EXISTS FOR (p:Page) REQUIRE p.name IS UNIQUE\")\n\n        # Create nodes and relationships\n        for link in links_data:\n            # Create or merge nodes and relationship\n            session.run(\n                \"\"\"\n                MERGE (from:Page {name: $from})\n                MERGE (to:Page {name: $to})\n                CREATE (from)-[:REFERENCES {context: $context}]->(to)\n                \"\"\",\n                parameters={\"from\": link[\"from\"], \"to\": link[\"to\"], \"context\": link[\"context\"]}\n            )\n\n    print(f\"Successfully loaded {len(links_data)} relationships into Neo4j\")\n```\n\n`load_wiki_network` takes the JSON file path and loads the link data into Neo4j. It first reads the JSON file containing all the link relationships, and open a Neo4j session, allowing us to run queries. Next, we run a few Cypher queries (SQL for Knowledge Graph) for each page:\n  * `**CREATE CONSTRAINT page_name IF NOT EXISTS**`**:** Enforce that each `Page` node must have a unique `name`, preventing duplicates.\n  * `**MERGE (from:Page {name: $from}) ...**`:`MERGE` either finds or creates a node. This ensures we don't create the same page node multiple times.\n  * `**CREATE (from)-[:REFERENCES {context: $context}]->(to)**`: Here we create a`REFERENCES` relationship between two pages. We store `context` as a property. In a real scenario, this might help with downstream tasks like summarization or topic analysis.\n\n\npython\n\n```\nload_wiki_network()\n```\n\nFinally, we load all the links we discovered into Neo4j, resulting in a rich network we can run PageRank on.\n_(After running, we might see: \"Successfully loaded 495 relationships into Neo4j\")_\nOnce, we have our graph, let's visualize it. There are a few way to visualize our newly created Knowledge Graph, but probably the easiest is using Neo4j browser. Switch back to Neo4j desktop, click on the arrow pointing down next to \"Open\", and click on \"Neo4j Browser\":\n![Screenshot of Neo4j desktop - Image by Author](../images/009.png)\nScreenshot of Neo4j desktop - Image by Author\nOnce you are in, run the following Cypher query:\nsql\n\n```\nMATCH (n) RETURN n\n```\n\nThis will fetch all the nodes, and plot our Knowledge Graph. In my case, mine looks like this:\n![Knowledge Graph containing random Wikipedia topics - Image by Author](../images/010.png)\nKnowledge Graph containing random Wikipedia topics - Image by Author\n### Resetting the Graph (Optional)\nIf at any point you want to start fresh, you can clear out all the data from Neo4j:\npython\n\n```\nwith driver.session() as session:\n    session.run(\"MATCH (n) DETACH DELETE n\")\n    print(\"Graph has been reset - all nodes and relationships deleted.\")\n```\n\n`**MATCH (n) DETACH DELETE n**`finds all nodes`n` and deletes them along with their relationships. This is a complete reset of the graph.\n### Implementing the PageRank Algorithm in Python\nNow that we have our graph of pages and links stored in Neo4j, we can implement PageRank from scratch. Remember how the math worked? We'll apply the iterative method we described, but this time reading real data from our Neo4j database.\npython\n\n```\ndef get_pages(tx):\n    result = tx.run(\"MATCH (p:Page) RETURN p.name AS name\")\n    return [record[\"name\"] for record in result]\n\ndef get_links(tx):\n    result = tx.run(\"MATCH (p1:Page)-[:LINKS_TO]->(p2:Page) RETURN p1.name AS from, p2.name AS to\")\n    links = {}\n    for record in result:\n        if record[\"from\"] not in links:\n            links[record[\"from\"]] = []\n        links[record[\"from\"]].append(record[\"to\"])\n    return links\n```\n\n`get_pages(tx)` runs a Cypher query to get all page names from the database. We return a list of these names.\n`get_links(tx)` queries all `LINKS_TO` relationships. We build a dictionary where each key is a page and each value is a list of pages it links to. This gives us the outbound link structure we need for PageRank.\npython\n\n```\ndef page_rank(pages, links, damping_factor=0.85, max_iterations=100, tol=1.0e-6):\n    n = len(pages)\n    ranks = np.ones(n) / n\n    page_index = {page: i for i, page in enumerate(pages)}\n```\n\nIt's finally time to create the function that will handle the PageRank algorithm. Let's start by setting:\n  * `n = len(pages)`**:** The total number of pages.\n  * `ranks = np.ones(n) / n`**:** Initialize all PageRank values equally, just like our earlier examples, giving each page 1/N initially.\n  * `page_index = {page: i ...}`**:** Create an index mapping from page names to their array index. This helps us store and access ranks efficiently.\n\n\npython\n\n```\nfor _ in range(max_iterations):\n        new_ranks = np.zeros(n)\n        for page, out_links in links.items():\n            if out_links:\n                share = ranks[page_index[page]] / len(out_links)\n                for linked_page in out_links:\n                    new_ranks[page_index[linked_page]] += share\n            else:\n                # If a page has no out-links, it is a \"dangling node\"\n                # We distribute its rank evenly across all pages\n                new_ranks += ranks[page_index[page]] / n\n```\n\nNext, we iterate multiple times until PageRank converges or we hit the limit. Each iteration starts with a blank slate. If the page has outbound links, we split its current rank among those links (like distributing \"votes\").\nFor each linked page, add the \"share\" of PageRank. If a page has no outbound links, it's a dangling node. We distribute its rank among all pages equally (this matches the theoretical fix for dangling nodes we discussed).\npython\n\n```\n        # Apply damping\n        new_ranks = damping_factor * new_ranks + (1 - damping_factor) / n\n```\n\nRemember our formula:\n![PageRank formula - Image by Author](../images/011.png)\nPageRank formula - Image by Author\nThe first part `(1-d)/N` is the \"random jump\" probability. We multiply our accumulated ranks by `d` and add the `(1-d)/N` term to every page.\nkotlin\n\n```\n        if np.linalg.norm(new_ranks - ranks, 1) < tol:\n            break\n        ranks = new_ranks\n```\n\nNext, we compute the difference between the new ranks and the old ones. If this difference (the \"update\") is very small, it means we've converged. If the change is less than the tolerance `tol`, we stop early. Our PageRank values have stabilized. Otherwise, we continue another iteration using the new ranks.\npython\n\n```\nreturn {page: ranks[page_index[page]] for page in pages}\n```\n\nFinally, we return a dictionary of {page_name: page_rank_value}, making it easy to see which pages have the highest PageRank.\npython\n\n```\nwith driver.session() as session:\n    pages = session.execute_read(get_pages)\n    links = session.execute_read(get_links)\n    ranks = page_rank(pages, links)\n    print(ranks)\n```\n\nNow, let's get all pages and links, and run our PageRank algorithm on the retrieved network, print out the PageRank scores for each page.\n### Connecting Back to the Math\nThis Python code reflects the math we discussed earlier. The `page_rank` function is essentially performing the iterative calculation of the eigenvector solution. Each iteration corresponds to one application of the formula:\n`R(t+1) = d*M*R(t) + (1-d)*1/N`\nWhere `M` is our link structure and `1/N` is the uniform distribution for the random jump. If you look closely at the code, every iteration updates the `new_ranks` in a way that mirrors applying `M` and then adding `(1-d)/N`. Once the difference between `new_ranks` and `ranks` is very small, we've found our stable vector: the PageRank values.\n## Conclusion\nNow, before we get too carried away, let's remember that PageRank isn't perfect, and has a few weak spots:\n  * **Link Spam** : Just like email spam, some folks try to game the system by creating fake links.\n  * **The \"**_**Rich Get Richer**_**\" Problem** : New websites start with low PageRank, making it harder for them to climb the rankings.\n\n\nSearch engines like Google now use incredibly complex systems that go way beyond just PageRank. But the core idea of PageRank - that the web's structure itself contains valuable information - is still at the heart of how we organize and find information online. Especially now in the AI world PageRank is coming back as a hot topic. For example, we see PageRank in Graph Neural Networks, which usePageRank-_like_ methods _to_ spread information through complex networks, and Graph RAG (Retrieval-Augmented Generation) where language models can use PageRank-style algorithms _to_ navigate vast knowledge graphs.\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](../images/body-8f73ac5a40c91a7b503f.jpeg)\nWritten By\n## [Cristian Leo](https://towardsdatascience.com/author/cristianleo120/)\n[See all from Cristian Leo](https://towardsdatascience.com/author/cristianleo120/)\n[Artificial Intelligence](https://towardsdatascience.com/tag/artificial-intelligence/)[Getting Started](https://towardsdatascience.com/tag/getting-started/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[Python](https://towardsdatascience.com/tag/python/)[Retrieval Augmented Gen](https://towardsdatascience.com/tag/retrieval-augmented-gen/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fthe-algorithm-that-made-google-google-3bbc2cfa8815%2F&title=The%20Algorithm%20That%20Made%20Google%20Google)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fthe-algorithm-that-made-google-google-3bbc2cfa8815%2F&title=The%20Algorithm%20That%20Made%20Google%20Google)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fthe-algorithm-that-made-google-google-3bbc2cfa8815%2F&text=The%20Algorithm%20That%20Made%20Google%20Google)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](../images/012.jpg)](https://towardsdatascience.com/imputation-of-missing-data-in-tables-with-datawig-2d7ab327ece2/)\n## [Imputation of Missing Data in Tables with DataWig](https://towardsdatascience.com/imputation-of-missing-data-in-tables-with-datawig-2d7ab327ece2/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nImplementing Amazon's DataWig in Python to impute missing values in tabular data\n[Kenneth Leung](https://towardsdatascience.com/author/kennethleungty/)\nAugust 24, 20222 min read\n  * [![](../images/013.jpg)](https://towardsdatascience.com/build-a-flask-heroku-mood-tracker-web-app-using-the-spotify-api-14b3b5c92ac9/)\n## [Build a Flask-Heroku Mood Tracker Web App Using the Spotify API](https://towardsdatascience.com/build-a-flask-heroku-mood-tracker-web-app-using-the-spotify-api-14b3b5c92ac9/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nA-Z project to generate mood scores based on the songs I listen to everyday and color my online mood tracker accordingly\n[Irene Chang](https://towardsdatascience.com/author/irenechang1510/)\nNovember 9, 20213 min read\n  * [![](../images/014.png)](https://towardsdatascience.com/teaching-ai-to-classify-time-series-patterns-with-synthetic-data-555d8e75ee8a/)\n## [Teaching AI to Classify Time-series Patterns with Synthetic Data](https://towardsdatascience.com/teaching-ai-to-classify-time-series-patterns-with-synthetic-data-555d8e75ee8a/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nHow to build and train an AI model to identify various common anomaly patterns in time-series data\n[Tirthajyoti Sarkar](https://towardsdatascience.com/author/tirthajyoti/)\nAugust 15, 20217 min read\n  * [![](../images/015.png)](https://towardsdatascience.com/sudoku-solver-48cb2744fbd4/)\n## [Sudoku Solver](https://towardsdatascience.com/sudoku-solver-48cb2744fbd4/)\n[Programming](https://towardsdatascience.com/category/programming/)\nSolving Sudoku With Python3 And Backtracking\n[Ben Bellerose](https://towardsdatascience.com/author/bellerb/)\nFebruary 26, 20224 min read\n  * [![](../images/016.jpg)](https://towardsdatascience.com/a-guide-to-exploit-random-forest-classifier-in-pyspark-46d6999cb5db/)\n## [A Guide to exploit Random Forest Classifier in PySpark](https://towardsdatascience.com/a-guide-to-exploit-random-forest-classifier-in-pyspark-46d6999cb5db/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nA practical explanatory guide for the classification of Iris flowers Output: Output: randomSplit() splits the...\n[Manusha Priyanjalee](https://towardsdatascience.com/author/manushapriyanjalee/)\nJune 1, 20211 min read\n  * [![](../images/017.jpeg)](https://towardsdatascience.com/what-you-need-to-know-before-taking-the-machine-learning-course-by-stanford-84fd7bf94628/)\n## [What you need to know before taking the Machine Learning course by Stanford](https://towardsdatascience.com/what-you-need-to-know-before-taking-the-machine-learning-course-by-stanford-84fd7bf94628/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nMachine Learning course by Andrew Ng & Stanford review\n[Dmytro Nikolaiev (Dimid)](https://towardsdatascience.com/author/andimid/)\nOctober 29, 20215 min read\n  * [![](../images/018.jpeg)](https://towardsdatascience.com/artificial-intelligence-and-terrorism-in-social-media-cf166adaf78e-2/)\n## [How does Facebook define Terrorism in Relation to Artificial Intelligence?](https://towardsdatascience.com/artificial-intelligence-and-terrorism-in-social-media-cf166adaf78e-2/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAI and Definitions of Terrorism In Social Media\n[Alex Moltzau](https://towardsdatascience.com/author/alexmoltzau/)\nJuly 25, 20190 min read\n  * [![](../images/019.png)](https://towardsdatascience.com/mixed-effects-machine-learning-with-gpboost-for-grouped-and-areal-spatial-econometric-data-b26f8bddd385/)\n## [Mixed Effects Machine Learning with GPBoost for Grouped and Areal Spatial Econometric Data](https://towardsdatascience.com/mixed-effects-machine-learning-with-gpboost-for-grouped-and-areal-spatial-econometric-data-b26f8bddd385/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nA demo using European GDP data\n[Fabio Sigrist](https://towardsdatascience.com/author/fabsig/)\nJune 21, 202314 min read\n  * [![](../images/020.jpg)](https://towardsdatascience.com/4-techniques-to-deal-with-missing-data-in-datasets-841f8a303395/)\n## [4 Techniques To Deal With Missing Data in Datasets](https://towardsdatascience.com/4-techniques-to-deal-with-missing-data-in-datasets-841f8a303395/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nSimple methods that can nullify the effects of missing values\n[Egor Howell](https://towardsdatascience.com/author/egorhowell/)\nSeptember 17, 20213 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500) How Relevance Models Foreshadowed Transformers for NLP ](https://towardsdatascience.com/how-relevance-models-foreshadowed-transformers-for-nlp/ \"How Relevance Models Foreshadowed Transformers for NLP\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n\n\n",
  "metadata": {
    "title": "The Algorithm That Made Google Google | Towards Data Science",
    "description": "How PageRank transformed how we searched the internet, and why it's still playing an important role in LLMs with Graph RAG.",
    "keywords": null,
    "author": "Cristian Leo",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "The Algorithm That Made Google Google",
    "og:description": "How PageRank transformed how we searched the internet, and why it's still playing an important role in LLMs with Graph RAG.",
    "og:url": "https://towardsdatascience.com/the-algorithm-that-made-google-google-3bbc2cfa8815/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1ZX3KFAhoIWBa1Oo2GvB9GQ.jpeg",
    "og:image:width": "1792",
    "og:image:height": "1024",
    "og:image:type": "image/jpeg",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Cristian Leo",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "17 min read",
    "article:published_time": "2024-12-18T17:46:57.000Z",
    "article:modified_time": "2024-12-18T17:46:57.000Z",
    "article:author": "https://towardsdatascience.com/author/cristianleo120/"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_000.txt",
      "chars": 149
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_001.txt",
      "chars": 262
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_002.txt",
      "chars": 225
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_003.txt",
      "chars": 124
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_004.txt",
      "chars": 237
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_005.txt",
      "chars": 103
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_006.txt",
      "chars": 72
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_007.txt",
      "chars": 288
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_008.txt",
      "chars": 594
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_009.txt",
      "chars": 18
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_010.txt",
      "chars": 329
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_011.txt",
      "chars": 103
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_012.txt",
      "chars": 954
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_013.txt",
      "chars": 20
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_014.txt",
      "chars": 19
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_015.txt",
      "chars": 152
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_016.txt",
      "chars": 436
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_017.txt",
      "chars": 187
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_018.txt",
      "chars": 521
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_019.txt",
      "chars": 98
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_020.txt",
      "chars": 99
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_021.txt",
      "chars": 57
    },
    {
      "language": "txt",
      "file": "attachments/3102ef8859a3/code/block_022.txt",
      "chars": 175
    }
  ],
  "images": [
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:56:53Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:56:53Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:56:53Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:56:53Z"
    }
  ],
  "audio": [],
  "videos": [
    {
      "url": "https://www.youtube.com/c/TowardsDataScience",
      "kind": "channel_reference",
      "status": "reference_only"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/cristianleo120/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/artificial-intelligence/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/getting-started/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/python/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/retrieval-augmented-gen/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/imputation-of-missing-data-in-tables-with-datawig-2d7ab327ece2/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/kennethleungty/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/build-a-flask-heroku-mood-tracker-web-app-using-the-spotify-api-14b3b5c92ac9/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/irenechang1510/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/teaching-ai-to-classify-time-series-patterns-with-synthetic-data-555d8e75ee8a/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/tirthajyoti/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/ai-engineer"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/machine-learning"
    },
    {
      "type": "external",
      "href": "https://github.com/cristianleoo/rag-knowledge-graph/blob/main/pagerank/demo.ipynb"
    },
    {
      "type": "external",
      "href": "https://neo4j.com/download/"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=The+Algorithm+That+Made+Google+Google&u=https%3A%2F%2Ftowardsdatascience.com%2Fthe-algorithm-that-made-google-google-3bbc2cfa8815%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=The+Algorithm+That+Made+Google+Google&url=https%3A%2F%2Ftowardsdatascience.com%2Fthe-algorithm-that-made-google-google-3bbc2cfa8815%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=The+Algorithm+That+Made+Google+Google&url=https%3A%2F%2Ftowardsdatascience.com%2Fthe-algorithm-that-made-google-google-3bbc2cfa8815%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    },
    {
      "type": "external",
      "href": "https://www.threads.net/@towardsdatascience"
    },
    {
      "type": "external",
      "href": "https://bsky.app/profile/towardsdatascience.com"
    },
    {
      "type": "external",
      "href": "https://thenewstack.io"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh"
    },
    {
      "type": "external",
      "href": "https://insightmediagroup.io/creator-network"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-20T17:29:27Z",
  "source_url": "https://towardsdatascience.com/the-algorithm-that-made-google-google-3bbc2cfa8815/",
  "delivery_status": "unverified",
  "discovery_status": "http_403",
  "missing_reason": "源页面未重新核验:http_403；已按保留正文补采图片",
  "repair_error": "",
  "actual_video_files": [],
  "expected_saved_body_images": 4,
  "image_discovery": "saved_markdown",
  "source_body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\n# The Algorithm That Made Google Google\nHow PageRank transformed how we searched the internet, and why it's still playing an important role in LLMs with Graph RAG.\n[Cristian Leo](https://towardsdatascience.com/author/cristianleo120/)\nDecember 18, 202417 min read\n![Image generated by DALL-E](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1ZX3KFAhoIWBa1Oo2GvB9GQ.jpeg)\nImage generated by DALL-E\nIn the late 1990s, two Stanford University graduate students, Larry Page and Sergey Brin, were working on their PhD research when they came across an interesting idea.\nLarry was particularly fascinated by the way web pages linked to one another. He saw the internet as a vast network of citations, similar to how academic papers reference each other. This sparked an idea: **what if a web page's importance could be measured by how many other pages linked to it?** But not just that - **what if the importance of those linking pages also mattered?**\nIntrigued by that idea, Larry started building an algorithm that would later be named \"PageRank\" (a clever play on his last name). The algorithm treated each link to a webpage as a vote of confidence, but with a twist - votes from more important pages carried more weight.\nSergey Brin, interested in Larry's concept, joined him. Together, they worked from their dorm rooms, building a search engine that would use this ranking system. At first, they called their project \"BackRub\" due to its analysis of backward links.\nAs their project grew, they realized they had something special on their hands. Their search engine was producing significantly better results than existing search engines of the time. In 1998, they decided to take a leave of absence from Stanford to focus on their project full-time.\nThey renamed their search engine \"Google\" - again a play, this time on the mathematical term \"googol\" (a number represented by 1 followed by 100 zeros) - reflecting their ambition to organize the vast amount of information on the web. With some initial funding from investors, including a $100,000 check written in their garage office, Google was officially born. The rest is history.\nLearn this step by step with the interactive [AI Engineer](https://roadmap.sh/ai-engineer) and [Machine Learning](https://roadmap.sh/machine-learning) roadmaps.\n## Breaking down PageRank\nNow, let's imagine we have 4 high school students: Amy, Bob, Charlie, and Diana. They are trying to decide who is more and less \"cool\", and how \"cool\" everyone is depends on how much support they get from the others. In particular, they have a pool of 100 \"cool\" points that is distributed to each student, hence 25 points each. Then, each student needs to give all their points to one or more students.\nLet's say:\n  * Amy vouches for Bob\n  * Bob vouches for Amy\n  * Charlie vouches for Amy and Diana\n  * Diana vouches for everyone\n\n\nAfter one round:\n  * Amy gets points from Bob (25) and half of Charlie's points (12.5) totaling 37.5 points\n  * Bob gets points from Amy (25) totaling 25 points\n  * Diana gets half of Charlie's points (12.5) totaling 12.5 points\n\n\nThen, the points get redistributed again and again until they stabilize. With this mechanism, the more popular you are, the more valuable your vouch is.\nThis is basically how PageRank works, just with websites instead of students and links instead of vouchers.\n### The Math Behind PageRank\nAt its heart, PageRank is based on a simple, but very powerful idea: the importance of a webpage can be determined by the quantity and quality of links pointing to it. This concept can be broken down into several key principles:\n  1. Every link to a page is a vote of confidence for that page.\n  2. The importance of the page casting the vote matters.\n  3. The more links a page casts, the less weight each link carries.\n\n\nFirst, we need to understand the concept of the \"random surfer.\" Imagine you're mindlessly clicking links on the internet (we've all been there, right?). You start on a random page, click a link, then another, and another. Occasionally, you get bored and just type in a new web address. This aimless journey is what we call the \"random surfer model.\"\nThe PageRank of a webpage is basically the probability that this random surfer will end up on that page after clicking around for a really, really long time (theoretically, an infinite amount of time, but let's not get too philosophical here).\nNow, here's where it gets interesting. The PageRank formula looks like this:\n![PageRank formula - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1xc7khIjkQOd4gyUJBArbUA.png)\nPageRank formula - Image by Author\nWhere:\n  * **PR(A)** is the PageRank of page A\n  * **d** is the damping factor (typically 0.85), which represents the probability that the random surfer will continue clicking links rather than jumping to a random page.\n  * **N** is the total number of pages in the network\n  * **PR(T_i)** is the PageRank of pages **T_i** which links to page A\n  * **C(T_i)** is the number of outbound links from page T_i\n  * **n** is the number of pages that link to page A\n\n\nNow, let's look at the two parts of this formula:\n![Left component in PageRank Formula - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1NE6oCj8Y-CGevke3IVb4dg.png)\nLeft component in PageRank Formula - Image by Author\nThis is the probability that our random surfer gets bored and jumps directly to page A. It's like rolling a die with N sides (where N is the number of pages on the internet) and landing on page A.\n![Right component in PageRank Formula - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/16MioJ7B6z7Uv3Msy6hSB_Q.png)\nRight component in PageRank Formula - Image by Author\nThis is the meaty part. It represents the probability of arriving at page A by following links. Each term in this sum is the PageRank of a page linking to A, divided by the number of links on that page.\nPageRank is also recursive, which means that page A depends on the PageRank of the pages linking to it, which in turn depend on the pages linking to them, and so on. It's like a never-ending chain of popularity contests!\nSo how do we actually calculate this? We use an iterative process:\n  1. Start by giving every page an equal PageRank (let's say 1/N).\n  2. Use our formula to calculate new PageRank values for each page.\n  3. Repeat step 2 until the values stop changing much between iterations.\n\n\nNow, you might be thinking, \"Wait a minute, what about pages with no outgoing links? Or pages that only link to each other?\" Great questions! These are what we call \"dangling nodes\" and \"rank sinks,\" and they can cause problems for our algorithm.\nFor dangling nodes (pages with no outgoing links), we usually pretend they link to all other pages equally. For rank sinks (groups of pages that only link to each other), the random jump factor (1-d) helps prevent them from hoarding all the PageRank.\nOk that seems easy when dealing with 4 pages, but how can we scale it to the whole internet? Here, we use a few tricks to make it manageable:\n  1. **Sparse Matrix Representation** : Most pages only link to a few others, so we can save a lot of memory by only storing the non-zero elements of our link matrix.\n  2. **Distributed Computing** : We can split up the calculation across many computers, each working on a different part of the web.\n  3. **Approximation Methods** : For really huge networks, we might use algorithms that give us a good estimate of PageRank without calculating it exactly for every single page.\n\n\nAnd remember, the web is constantly changing. New pages are created, old ones disappear, links are added and removed. So Google (and other search engines) need to keep updating their PageRank calculations all the time.\n### Practical example\nLet's start with a small web of just four pages to illustrate how PageRank actually works in practice. Imagine we have pages A, B, C, and D with the following link structure:\n  * Page A links to B and C\n  * Page B links to C and D\n  * Page C links to A\n  * Page D links to C\n\n\n![4 pages example visualized in a Knowledge Graph - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1BJLh5ZZmTr7l86VDVOB03A.png)\n4 pages example visualized in a Knowledge Graph - Image by Author\nNow, let's calculate the PageRank for these pages step by step. We'll use a damping factor (d) of 0.85, which is the typical value used in practice.\n**Step 1: Initialize PageRank** We start by giving each page an equal PageRank. Since we have 4 pages, each page starts with a PageRank of 1/4 = 0.25.\n![Equal probabilities among the 4 pages - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1-9TvA7hIJJ7j6q4mO9R5yQ.png)\nEqual probabilities among the 4 pages - Image by Author\n**Step 2: Calculate new PageRank values** Now we'll use our PageRank formula for each page. Remember, the formula is:\n![Calculate new page rank values using PageRank formula - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1xc7khIjkQOd4gyUJBArbUA.png)\nCalculate new page rank values using PageRank formula - Image by Author\nWhere N is the total number of pages (4 in our case), Y are the pages linking to X, and C(Y) is the number of outbound links from Y.\n![First iteration of calculation for 4 pages - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1QUJ9IkkYNL9wFncsZbL1VA.png)\nFirst iteration of calculation for 4 pages - Image by Author\n**Step 3: Iterate** Now we use these new PageRank values and repeat the calculation. Let's do one more iteration:\n![Second iteration of calculation for 4 pages - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/107DgDJFbW0rVPq31pp32Yw.png)\nSecond iteration of calculation for 4 pages - Image by Author\nWe would continue this process until the values converge (change very little between iterations). Indeed, the PageRank algorithm is guaranteed to converge because of the properties of the Google matrix (the matrix representing the web's link structure plus the damping factor). This matrix is stochastic (each column sums to 1) and irreducible (there's a path between any two pages), which ensures convergence to a unique solution.\n## 4: From Math to Code\nNow, it's time to switch from theory to practice with a Python implementation of PageRank on a Knowledge Graph. Here, we will:\n  1. Connect to a Neo4j graph database.\n  2. Create a small sample graph structure to understand the basics.\n  3. Crawl a subset of Wikipedia pages to build a larger, more realistic network of links.\n  4. Load this network into Neo4j, creating nodes for pages and relationships for links.\n  5. Implement PageRank in Python from scratch and run it on the graph data stored in Neo4j.\n\n\nYou can find all the code we will cover in this section on this Jupyter Notebook:\n> [**rag-knowledge-graph/pagerank/demo.ipynb at main · cristianleoo/rag-knowledge-graph**](https://github.com/cristianleoo/rag-knowledge-graph/blob/main/pagerank/demo.ipynb)\n### Setting up the Neo4j Connection\nFirst, we need to set up a connection to our Neo4j database. Neo4j is a graph database that stores data in nodes (think webpages) and relationships (think hyperlinks). Connecting to it allows us to store our crawled data and run queries to build the link structure we need for PageRank. If you read my previous Graph RAG article, you would already know how to set it up, so just jump straight to the code. If not, let's first go over the Neo4j installation process. We will be using Neo4j just because it provides an easy installation and free option for local hosting (I don't have any sort of affiliation with it).\nTo install Neo4j simply visit the [Neo4j Desktop Download Page](https://neo4j.com/download/) and click Download. Open **Neo4j Desktop** after installation. Sign in or create a **Neo4j account** (required to activate the software).\nOnce logged in, create a **New Project** :\n  * Click on the `**+**`button in the top-left corner.\n  * Name your project (e.g., \"PageRank\").\n\n\nInside your project, click on `**Add Database**`. Select**Local DBMS** and click **Create a Local Graph**.\nConfigure your database:\n  * **Name** : Enter a name (e.g., `neo4j`).\n  * **Password** : Set a password (e.g., `pagerank`). Remember this password for later.\n\n\nClick **Create** to initialize the database.\nNow, let's move on to the code:\npython\n\n```\nfrom neo4j import GraphDatabase\nimport json\nimport wikipediaapi\nimport random\nfrom tqdm import tqdm\nfrom collections import deque\nimport numpy as np\n```\n\nWe import the `GraphDatabase` class to connect to a Neo4j database and run queries against it. This will be our main class to handle operation against our Knowledge Graph.\nNext, we import a series of Python libraries: `json` for reading and writing data in JSON format, `wikipediaapi` for accessing Wikipedia pages, `random` for random selection of links, `tqdm` for progress bars, `deque` (a double-ended queue) for efficiently handling lists we will treat like queues, and `numpy` for mathematical operations.\npython\n\n```\n# Connect to Neo4j\nuri = \"bolt://localhost:7687\"  # Change this to your Neo4j URI\nusername = \"neo4j\"  # Change this to your Neo4j username\npassword = \"pagerank\"  # Change this to your Neo4j password\n\ndriver = GraphDatabase.driver(uri, auth=(username, password))\n```\n\nLet's define the connection for the Neo4j instance. In a production environment, you'd make sure these credentials are secure, but for our demonstration, we'll keep it simple.\nNext, we create a `driver` object that lets us open sessions to the database and run queries. Think of this as \"plugging in\" your Python code to the Neo4j database engine.\n### Crawling Wikipedia\nFor our example, we will crawl 100 pages from Wikipedia, starting from a single article. We'll follow links to other articles, pick a few at random, and build a larger link network. This mimics the random surfer model we discussed, except we're not just simulating a random surfer's journey - we're actually collecting the links themselves.\npython\n\n```\ndef crawl_wiki_network(start_title, max_articles=100, max_links_per_article=5):\n    # Initialize Wikipedia API\n    wiki = wikipediaapi.Wikipedia(\n        'RAG Knowledge Graph (cristianleonardi@gmail.com)',\n        'en'\n    )\n```\n\nThis `crawl_wiki_network` **** function starts at a given Wikipedia article and crawls through linked pages. Inside it, we create a Wikipedia API object. The arguments identify our application and language (English in this case).\npython\n\n```\n    # Track visited pages and links\n    visited_pages = set()\n    links_data = []\n    pages_to_visit = deque([start_title])\n```\n\nLet's initialize `visited_pages = set()` to keep track of which pages we've already processed so we don't repeat work. Next, `links_data = []` will store information about the links we discover: from which page the link came, to which page it goes, and some context.\nAlso, we start with a queue that initially contains just one page: the page we start from (e.g., \"Artificial intelligence\"). We'll pull pages off this queue and explore them.\npython\n\n```\n    with tqdm(total=max_articles) as pbar:\n        while pages_to_visit and len(visited_pages) < max_articles:\n            current_title = pages_to_visit.popleft()\n\n            if current_title in visited_pages:\n                continue\n```\n\nWe use `tqdm` for a nice progress bar so we know how many articles we've processed out of `max_articles`. We continue crawling as long as there are pages to visit and we haven't hit our limit of articles via the `while` loop.\n`popleft()` removes the next page title from our queue, and in case we've already seen this page, skip it to avoid loops.\npython\n\n```\n            page = wiki.page(current_title)\n            if not page.exists():\n                continue\n```\n\nNext, we fetch the page from Wikipedia, and in case of broken links we skip the page.\npython\n\n```\n            visited_pages.add(current_title)\n            pbar.update(1)\n```\n\nOnce, we visit the new page, we add it to the `visited_pages` set, and update our progress bar, showing that we've successfully processed another article.\npython\n\n```\n            # Get all links from the page\n            page_links = list(page.links.items())\n\n            # Randomly select a subset of links\n            selected_links = random.sample(\n                page_links, \n                min(max_links_per_article, len(page_links))\n            )\n```\n\nNext, we get all the links found on the current page, and pick a few links at random, up to `max_links_per_article`. This mimics the idea that our random surfer won't follow every single link, just a handful.\npython\n\n```\n            # Process selected links\n            for link_title, link_page in selected_links:\n                if link_page.exists():\n                    # Add link to queue for future processing\n                    pages_to_visit.append(link_title)\n\n                    # Get the first paragraph as context\n                    context = link_page.summary.split('n')[0] if link_page.summary else \"\"\n\n                    links_data.append({\n                        \"from\": current_title,\n                        \"to\": link_title,\n                        \"context\": context\n                    })\n```\n\nNext, we iterate over each chosen link, and for each valid link (skipping broken as before):\n  * We add it to our queue, so we can explore it in a future iteration.\n  * Extract a bit of context (like a snippet of text) from the linked page, giving us more info if needed.\n  * Store the \"from → to\" link in `links_data`. This data will later help us build a graph in Neo4j and eventually run PageRank.\n\n\npython\n\n```\nreturn links_data\n```\n\nAfter we've reached our maximum number of articles or run out of links, we return all the link data we collected.\n### Saving the Crawled Network\nNow we have a crawler that returns link data. Let's save this data as a JSON file for future use.\npython\n\n```\ndef save_network(start_title, output_file=\"wikipedia_network.json\"):\n    links_data = crawl_wiki_network(start_title)\n    if links_data:\n        with open(output_file, 'w', encoding='utf-8') as f:\n            json.dump(links_data, f, indent=2, ensure_ascii=False)\n        print(f\"Saved {len(links_data)} links to {output_file}\")\n```\n\nThis function runs the crawler, takes the returned `links_data`, and writes it out to a JSON file.\npython\n\n```\n# You can start with any article\nstart_article = \"Artificial intelligence\"\nsave_network(start_article)\n```\n\nWe choose a starting point for our crawl - here it's \"Artificial intelligence.\" We could pick any article to begin the chain, and run the whole process and save the results.\n_(As the crawler runs, we'll see a progress bar. Eventually, it prints something like: \"Saved 495 links to wikipedia _network.json\".)_\n### Loading the Network into Neo4j\nNow that we have a JSON file full of link data, let's load it into Neo4j so we can store and query the network there. This will let us handle larger datasets more easily and perform efficient lookups when we implement PageRank.\npython\n\n```\ndef load_wiki_network(file_path=\"wikipedia_network.json\"):\n    # Read the JSON file\n    with open(file_path, 'r', encoding='utf-8') as f:\n        links_data = json.load(f)\n\n    # Connect to Neo4j and load the data\n    with driver.session() as session:\n        # Create unique constraints if they don't exist\n        session.run(\"CREATE CONSTRAINT page_name IF NOT EXISTS FOR (p:Page) REQUIRE p.name IS UNIQUE\")\n\n        # Create nodes and relationships\n        for link in links_data:\n            # Create or merge nodes and relationship\n            session.run(\n                \"\"\"\n                MERGE (from:Page {name: $from})\n                MERGE (to:Page {name: $to})\n                CREATE (from)-[:REFERENCES {context: $context}]->(to)\n                \"\"\",\n                parameters={\"from\": link[\"from\"], \"to\": link[\"to\"], \"context\": link[\"context\"]}\n            )\n\n    print(f\"Successfully loaded {len(links_data)} relationships into Neo4j\")\n```\n\n`load_wiki_network` takes the JSON file path and loads the link data into Neo4j. It first reads the JSON file containing all the link relationships, and open a Neo4j session, allowing us to run queries. Next, we run a few Cypher queries (SQL for Knowledge Graph) for each page:\n  * `**CREATE CONSTRAINT page_name IF NOT EXISTS**`**:** Enforce that each `Page` node must have a unique `name`, preventing duplicates.\n  * `**MERGE (from:Page {name: $from}) ...**`:`MERGE` either finds or creates a node. This ensures we don't create the same page node multiple times.\n  * `**CREATE (from)-[:REFERENCES {context: $context}]->(to)**`: Here we create a`REFERENCES` relationship between two pages. We store `context` as a property. In a real scenario, this might help with downstream tasks like summarization or topic analysis.\n\n\npython\n\n```\nload_wiki_network()\n```\n\nFinally, we load all the links we discovered into Neo4j, resulting in a rich network we can run PageRank on.\n_(After running, we might see: \"Successfully loaded 495 relationships into Neo4j\")_\nOnce, we have our graph, let's visualize it. There are a few way to visualize our newly created Knowledge Graph, but probably the easiest is using Neo4j browser. Switch back to Neo4j desktop, click on the arrow pointing down next to \"Open\", and click on \"Neo4j Browser\":\n![Screenshot of Neo4j desktop - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/14HgXqrLXbjlTPRdgq4xlUA.png)\nScreenshot of Neo4j desktop - Image by Author\nOnce you are in, run the following Cypher query:\nsql\n\n```\nMATCH (n) RETURN n\n```\n\nThis will fetch all the nodes, and plot our Knowledge Graph. In my case, mine looks like this:\n![Knowledge Graph containing random Wikipedia topics - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1m2Eo6G9y2ywCRwXEjWZgMA.png)\nKnowledge Graph containing random Wikipedia topics - Image by Author\n### Resetting the Graph (Optional)\nIf at any point you want to start fresh, you can clear out all the data from Neo4j:\npython\n\n```\nwith driver.session() as session:\n    session.run(\"MATCH (n) DETACH DELETE n\")\n    print(\"Graph has been reset - all nodes and relationships deleted.\")\n```\n\n`**MATCH (n) DETACH DELETE n**`finds all nodes`n` and deletes them along with their relationships. This is a complete reset of the graph.\n### Implementing the PageRank Algorithm in Python\nNow that we have our graph of pages and links stored in Neo4j, we can implement PageRank from scratch. Remember how the math worked? We'll apply the iterative method we described, but this time reading real data from our Neo4j database.\npython\n\n```\ndef get_pages(tx):\n    result = tx.run(\"MATCH (p:Page) RETURN p.name AS name\")\n    return [record[\"name\"] for record in result]\n\ndef get_links(tx):\n    result = tx.run(\"MATCH (p1:Page)-[:LINKS_TO]->(p2:Page) RETURN p1.name AS from, p2.name AS to\")\n    links = {}\n    for record in result:\n        if record[\"from\"] not in links:\n            links[record[\"from\"]] = []\n        links[record[\"from\"]].append(record[\"to\"])\n    return links\n```\n\n`get_pages(tx)` runs a Cypher query to get all page names from the database. We return a list of these names.\n`get_links(tx)` queries all `LINKS_TO` relationships. We build a dictionary where each key is a page and each value is a list of pages it links to. This gives us the outbound link structure we need for PageRank.\npython\n\n```\ndef page_rank(pages, links, damping_factor=0.85, max_iterations=100, tol=1.0e-6):\n    n = len(pages)\n    ranks = np.ones(n) / n\n    page_index = {page: i for i, page in enumerate(pages)}\n```\n\nIt's finally time to create the function that will handle the PageRank algorithm. Let's start by setting:\n  * `n = len(pages)`**:** The total number of pages.\n  * `ranks = np.ones(n) / n`**:** Initialize all PageRank values equally, just like our earlier examples, giving each page 1/N initially.\n  * `page_index = {page: i ...}`**:** Create an index mapping from page names to their array index. This helps us store and access ranks efficiently.\n\n\npython\n\n```\nfor _ in range(max_iterations):\n        new_ranks = np.zeros(n)\n        for page, out_links in links.items():\n            if out_links:\n                share = ranks[page_index[page]] / len(out_links)\n                for linked_page in out_links:\n                    new_ranks[page_index[linked_page]] += share\n            else:\n                # If a page has no out-links, it is a \"dangling node\"\n                # We distribute its rank evenly across all pages\n                new_ranks += ranks[page_index[page]] / n\n```\n\nNext, we iterate multiple times until PageRank converges or we hit the limit. Each iteration starts with a blank slate. If the page has outbound links, we split its current rank among those links (like distributing \"votes\").\nFor each linked page, add the \"share\" of PageRank. If a page has no outbound links, it's a dangling node. We distribute its rank among all pages equally (this matches the theoretical fix for dangling nodes we discussed).\npython\n\n```\n        # Apply damping\n        new_ranks = damping_factor * new_ranks + (1 - damping_factor) / n\n```\n\nRemember our formula:\n![PageRank formula - Image by Author](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/12/1xc7khIjkQOd4gyUJBArbUA.png)\nPageRank formula - Image by Author\nThe first part `(1-d)/N` is the \"random jump\" probability. We multiply our accumulated ranks by `d` and add the `(1-d)/N` term to every page.\nkotlin\n\n```\n        if np.linalg.norm(new_ranks - ranks, 1) < tol:\n            break\n        ranks = new_ranks\n```\n\nNext, we compute the difference between the new ranks and the old ones. If this difference (the \"update\") is very small, it means we've converged. If the change is less than the tolerance `tol`, we stop early. Our PageRank values have stabilized. Otherwise, we continue another iteration using the new ranks.\npython\n\n```\nreturn {page: ranks[page_index[page]] for page in pages}\n```\n\nFinally, we return a dictionary of {page_name: page_rank_value}, making it easy to see which pages have the highest PageRank.\npython\n\n```\nwith driver.session() as session:\n    pages = session.execute_read(get_pages)\n    links = session.execute_read(get_links)\n    ranks = page_rank(pages, links)\n    print(ranks)\n```\n\nNow, let's get all pages and links, and run our PageRank algorithm on the retrieved network, print out the PageRank scores for each page.\n### Connecting Back to the Math\nThis Python code reflects the math we discussed earlier. The `page_rank` function is essentially performing the iterative calculation of the eigenvector solution. Each iteration corresponds to one application of the formula:\n`R(t+1) = d*M*R(t) + (1-d)*1/N`\nWhere `M` is our link structure and `1/N` is the uniform distribution for the random jump. If you look closely at the code, every iteration updates the `new_ranks` in a way that mirrors applying `M` and then adding `(1-d)/N`. Once the difference between `new_ranks` and `ranks` is very small, we've found our stable vector: the PageRank values.\n## Conclusion\nNow, before we get too carried away, let's remember that PageRank isn't perfect, and has a few weak spots:\n  * **Link Spam** : Just like email spam, some folks try to game the system by creating fake links.\n  * **The \"**_**Rich Get Richer**_**\" Problem** : New websites start with low PageRank, making it harder for them to climb the rankings.\n\n\nSearch engines like Google now use incredibly complex systems that go way beyond just PageRank. But the core idea of PageRank - that the web's structure itself contains valuable information - is still at the heart of how we organize and find information online. Especially now in the AI world PageRank is coming back as a hot topic. For example, we see PageRank in Graph Neural Networks, which usePageRank-_like_ methods _to_ spread information through complex networks, and Graph RAG (Retrieval-Augmented Generation) where language models can use PageRank-style algorithms _to_ navigate vast knowledge graphs.\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657505387_wlyc0o.jpeg)\nWritten By\n## [Cristian Leo](https://towardsdatascience.com/author/cristianleo120/)\n[See all from Cristian Leo](https://towardsdatascience.com/author/cristianleo120/)\n[Artificial Intelligence](https://towardsdatascience.com/tag/artificial-intelligence/)[Getting Started](https://towardsdatascience.com/tag/getting-started/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[Python](https://towardsdatascience.com/tag/python/)[Retrieval Augmented Gen](https://towardsdatascience.com/tag/retrieval-augmented-gen/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fthe-algorithm-that-made-google-google-3bbc2cfa8815%2F&title=The%20Algorithm%20That%20Made%20Google%20Google)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fthe-algorithm-that-made-google-google-3bbc2cfa8815%2F&title=The%20Algorithm%20That%20Made%20Google%20Google)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fthe-algorithm-that-made-google-google-3bbc2cfa8815%2F&text=The%20Algorithm%20That%20Made%20Google%20Google)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/08/0UDAtYOTEL_y4LlAW-scaled.jpg)](https://towardsdatascience.com/imputation-of-missing-data-in-tables-with-datawig-2d7ab327ece2/)\n## [Imputation of Missing Data in Tables with DataWig](https://towardsdatascience.com/imputation-of-missing-data-in-tables-with-datawig-2d7ab327ece2/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nImplementing Amazon's DataWig in Python to impute missing values in tabular data\n[Kenneth Leung](https://towardsdatascience.com/author/kennethleungty/)\nAugust 24, 20222 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/11/09e-O5bruClQjVVQh-scaled.jpg)](https://towardsdatascience.com/build-a-flask-heroku-mood-tracker-web-app-using-the-spotify-api-14b3b5c92ac9/)\n## [Build a Flask-Heroku Mood Tracker Web App Using the Spotify API](https://towardsdatascience.com/build-a-flask-heroku-mood-tracker-web-app-using-the-spotify-api-14b3b5c92ac9/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nA-Z project to generate mood scores based on the songs I listen to everyday and color my online mood tracker accordingly\n[Irene Chang](https://towardsdatascience.com/author/irenechang1510/)\nNovember 9, 20213 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/08/1fhQEryc7PtNv9M9l963d5A.png)](https://towardsdatascience.com/teaching-ai-to-classify-time-series-patterns-with-synthetic-data-555d8e75ee8a/)\n## [Teaching AI to Classify Time-series Patterns with Synthetic Data](https://towardsdatascience.com/teaching-ai-to-classify-time-series-patterns-with-synthetic-data-555d8e75ee8a/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nHow to build and train an AI model to identify various common anomaly patterns in time-series data\n[Tirthajyoti Sarkar](https://towardsdatascience.com/author/tirthajyoti/)\nAugust 15, 20217 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/02/11wVvuJUuCTDMg-uT8g3ig.png)](https://towardsdatascience.com/sudoku-solver-48cb2744fbd4/)\n## [Sudoku Solver](https://towardsdatascience.com/sudoku-solver-48cb2744fbd4/)\n[Programming](https://towardsdatascience.com/category/programming/)\nSolving Sudoku With Python3 And Backtracking\n[Ben Bellerose](https://towardsdatascience.com/author/bellerb/)\nFebruary 26, 20224 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/0FIj65s952XFWEoFZ-scaled.jpg)](https://towardsdatascience.com/a-guide-to-exploit-random-forest-classifier-in-pyspark-46d6999cb5db/)\n## [A Guide to exploit Random Forest Classifier in PySpark](https://towardsdatascience.com/a-guide-to-exploit-random-forest-classifier-in-pyspark-46d6999cb5db/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nA practical explanatory guide for the classification of Iris flowers Output: Output: randomSplit() splits the...\n[Manusha Priyanjalee](https://towardsdatascience.com/author/manushapriyanjalee/)\nJune 1, 20211 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/10/1kigPUGyriodovbOTcxdEhw.jpeg)](https://towardsdatascience.com/what-you-need-to-know-before-taking-the-machine-learning-course-by-stanford-84fd7bf94628/)\n## [What you need to know before taking the Machine Learning course by Stanford](https://towardsdatascience.com/what-you-need-to-know-before-taking-the-machine-learning-course-by-stanford-84fd7bf94628/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nMachine Learning course by Andrew Ng & Stanford review\n[Dmytro Nikolaiev (Dimid)](https://towardsdatascience.com/author/andimid/)\nOctober 29, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2019/07/1Or6uS5XMGeYe22ISia5CiA-scaled.jpeg)](https://towardsdatascience.com/artificial-intelligence-and-terrorism-in-social-media-cf166adaf78e-2/)\n## [How does Facebook define Terrorism in Relation to Artificial Intelligence?](https://towardsdatascience.com/artificial-intelligence-and-terrorism-in-social-media-cf166adaf78e-2/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAI and Definitions of Terrorism In Social Media\n[Alex Moltzau](https://towardsdatascience.com/author/alexmoltzau/)\nJuly 25, 20190 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/06/1p5JPjgSsBUu8eu0utX3iRw.png)](https://towardsdatascience.com/mixed-effects-machine-learning-with-gpboost-for-grouped-and-areal-spatial-econometric-data-b26f8bddd385/)\n## [Mixed Effects Machine Learning with GPBoost for Grouped and Areal Spatial Econometric Data](https://towardsdatascience.com/mixed-effects-machine-learning-with-gpboost-for-grouped-and-areal-spatial-econometric-data-b26f8bddd385/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nA demo using European GDP data\n[Fabio Sigrist](https://towardsdatascience.com/author/fabsig/)\nJune 21, 202314 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/09/03dU5rx6iYuAX44R7-scaled.jpg)](https://towardsdatascience.com/4-techniques-to-deal-with-missing-data-in-datasets-841f8a303395/)\n## [4 Techniques To Deal With Missing Data in Datasets](https://towardsdatascience.com/4-techniques-to-deal-with-missing-data-in-datasets-841f8a303395/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nSimple methods that can nullify the effects of missing values\n[Egor Howell](https://towardsdatascience.com/author/egorhowell/)\nSeptember 17, 20213 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500) How Relevance Models Foreshadowed Transformers for NLP ](https://towardsdatascience.com/how-relevance-models-foreshadowed-transformers-for-nlp/ \"How Relevance Models Foreshadowed Transformers for NLP\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n\n\n",
  "body_base_path": "attachments/3102ef8859a3/pages/",
  "body_markdown_path": "attachments/3102ef8859a3/pages/archived-body.md",
  "local_html": "attachments/3102ef8859a3/pages/archived-body.html",
  "body_source": "prior_capture"
}