### Set OpenAI API Key for fuzzylink in R Source: https://github.com/joeornstein/fuzzylink/blob/main/README.md Configures the fuzzylink package to use the OpenAI API for language models. Replace 'YOUR API KEY GOES HERE' with your actual OpenAI API key. The 'install = TRUE' argument may handle necessary setup for the package to use the key. ```r library(fuzzylink) openai_api_key('YOUR API KEY GOES HERE', install = TRUE) ``` -------------------------------- ### Set Mistral API Key for fuzzylink in R Source: https://github.com/joeornstein/fuzzylink/blob/main/README.md Configures the fuzzylink package to use the Mistral API for language models. Replace 'YOUR API KEY GOES HERE' with your actual Mistral API key. The 'install = TRUE' argument may handle necessary setup for the package to use the key. ```r library(fuzzylink) mistral_api_key('YOUR API KEY GOES HERE', install = TRUE) ``` -------------------------------- ### Configure API Keys for R Services Source: https://context7.com/joeornstein/fuzzylink/llms.txt Functions to set or install API keys for OpenAI, Mistral, and Anthropic into the .Renviron file. These functions support session-based or persistent storage with options to overwrite existing keys. ```r library(fuzzylink) # OpenAI openai_api_key("sk-your-api-key-here", install = TRUE) # Mistral mistral_api_key("your-mistral-api-key", install = TRUE) # Anthropic anthropic_api_key("your-anthropic-api-key", install = TRUE) # Verify readRenviron("~/.Renviron") Sys.getenv("OPENAI_API_KEY") ``` -------------------------------- ### Install fuzzylink Development Version from GitHub in R Source: https://github.com/joeornstein/fuzzylink/blob/main/README.md Installs the development version of the fuzzylink R package directly from its GitHub repository. This is useful for accessing the latest features or bug fixes before they are released on CRAN. Requires the devtools package. ```r # install.packages("devtools") devtools::install_github("joeornstein/fuzzylink") ``` -------------------------------- ### Fuzzy Matching with Blocking Variables in R Source: https://context7.com/joeornstein/fuzzylink/llms.txt Demonstrates how to use the `fuzzylink` function with blocking variables to improve efficiency by limiting comparisons to records within the same state. It also shows examples of using custom instructions, different LLM models (GPT-3.5 Turbo, Mistral), and a random forest learner. ```r library(fuzzylink) dfA_with_state <- tribble( ~name, ~state, ~age, 'Joe Biden', 'Delaware', 81, 'Donald Trump', 'New York', 77, 'Barack Obama', 'Illinois', 62, 'George W. Bush', 'Texas', 77, 'Bill Clinton', 'Arkansas', 77 ) dfB_with_state <- tribble( ~name, ~state, ~hobby, 'Joseph Robinette Biden', 'Delaware', 'Football', 'Donald John Trump', 'Florida', 'Golf', 'Barack Hussein Obama', 'Illinois', 'Basketball', 'George Walker Bush', 'Texas', 'Reading', 'William Jefferson Clinton', 'Arkansas', 'Saxophone' ) # Only compare records within same state (reduces API calls) df_blocked <- fuzzylink( dfA_with_state, dfB_with_state, by = 'name', blocking.variables = 'state', record_type = 'person' ) # Using custom instructions and different model df_custom <- fuzzylink( dfA, dfB, by = 'name', record_type = 'US president', instructions = 'Names may include middle names or nicknames. Bill is short for William.', model = 'gpt-3.5-turbo-instruct', # Lower cost option embedding_model = 'text-embedding-3-small', verbose = FALSE ) # Using Mistral models df_mistral <- fuzzylink( dfA, dfB, by = 'name', record_type = 'person', model = 'mistral-large-latest', embedding_model = 'mistral-embed' ) # Using random forest learner for more complex matching df_rf <- fuzzylink( dfA, dfB, by = 'name', record_type = 'person', learner = 'ranger', max_labels = 5000 ) ``` -------------------------------- ### Install fuzzylink Package from CRAN in R Source: https://github.com/joeornstein/fuzzylink/blob/main/README.md Installs the fuzzylink R package from the Comprehensive R Archive Network (CRAN). This is the standard method for installing stable releases of R packages. ```r install.packages('fuzzylink') ``` -------------------------------- ### Set Anthropic API Key for fuzzylink in R Source: https://github.com/joeornstein/fuzzylink/blob/main/README.md Configures the fuzzylink package to use the Anthropic API (for Claude models) for language models. Replace 'YOUR API KEY GOES HERE' with your actual Anthropic API key. The 'install = TRUE' argument may handle necessary setup for the package to use the key. ```r library(fuzzylink) anthropic_api_key('YOUR API KEY GOES HERE', install = TRUE) ``` -------------------------------- ### Perform Record Linkage with Fuzzylink Source: https://github.com/joeornstein/fuzzylink/blob/main/README.md Demonstrates how to initialize datasets and execute the fuzzylink function with blocking variables to restrict matches to specific subsets of data. ```R library(tidyverse) dfA <- tribble(~name, ~state, ~age, 'Joe Biden', 'Delaware', 81, 'Donald Trump', 'New York', 77, 'Barack Obama', 'Illinois', 62, 'George W. Bush', 'Texas', 77, 'Bill Clinton', 'Arkansas', 77) dfB <- tribble(~name, ~state, ~hobby, 'Joseph Robinette Biden', 'Delaware', 'Football', 'Donald John Trump ', 'Florida', 'Golf', 'Barack Hussein Obama', 'Illinois', 'Basketball', 'George Walker Bush', 'Texas', 'Reading', 'William Jefferson Clinton', 'Arkansas', 'Saxophone', 'George Herbert Walker Bush', 'Texas', 'Skydiving', 'Biff Tannen', 'California', 'Bullying', 'Joe Riley', 'South Carolina', 'Jogging') df <- fuzzylink(dfA, dfB, by = 'name', blocking.variables = 'state', record_type = 'person') print(df) ``` -------------------------------- ### Computing Similarity Matrix with get_similarity_matrix in R Source: https://context7.com/joeornstein/fuzzylink/llms.txt Demonstrates the `get_similarity_matrix` function for calculating pairwise cosine similarities between sets of strings using precomputed embeddings. It highlights efficient, parallelized matrix multiplication for performance. ```r library(fuzzylink) # Get embeddings first embeddings <- get_embeddings(c('UPS', 'USPS', 'FedEx', 'Postal Service', 'United Parcel')) # Compute full similarity matrix (all pairs) sim_full <- get_similarity_matrix(embeddings) sim_full #> UPS USPS FedEx Postal Service United Parcel #> UPS 1.0000000 0.6789012 0.5432109 0.5678901 0.9012345 #> USPS 0.6789012 1.0000000 0.4567890 0.8901234 0.5678901 #> FedEx 0.5432109 0.4567890 1.0000000 0.4321098 0.5123456 #> Postal Service 0.5678901 0.8901234 0.4321098 1.0000000 0.4890123 #> United Parcel 0.9012345 0.5678901 0.5123456 0.4890123 1.0000000 ``` -------------------------------- ### Generating Text Embeddings with get_embeddings in R Source: https://context7.com/joeornstein/fuzzylink/llms.txt Shows how to use the `get_embeddings` function to retrieve text embeddings from OpenAI or Mistral APIs. It covers batching for rate limit handling, specifying embedding dimensions, using Mistral embeddings, and disabling parallel processing. ```r library(fuzzylink) # Get embeddings for a vector of strings embeddings <- get_embeddings(c('dog', 'cat', 'canine', 'feline', 'puppy', 'kitten')) # Returns matrix with strings as row names dim(embeddings) #> [1] 6 256 rownames(embeddings) #> [1] "dog" "cat" "canine" "feline" "puppy" "kitten" # Compare semantic similarity using dot product embeddings['dog',] |> dot(embeddings['canine',]) #> [1] 0.8934567 embeddings['dog',] |> dot(embeddings['feline',]) #> [1] 0.5123456 embeddings['dog',] |> dot(embeddings['puppy',]) #> [1] 0.9234567 # Use smaller embedding dimensions for faster processing embeddings_small <- get_embeddings( c('apple', 'orange', 'banana'), model = 'text-embedding-3-small', dimensions = 128 ) # Use Mistral embeddings (always returns 1024 dimensions) embeddings_mistral <- get_embeddings( c('hello', 'world'), model = 'mistral-embed' ) dim(embeddings_mistral) #> [1] 2 1024 # Disable parallel processing to avoid rate limits embeddings_sequential <- get_embeddings( c('foo', 'bar', 'baz'), parallel = FALSE ) ``` -------------------------------- ### Entity Matching with check_match Function in R Source: https://context7.com/joeornstein/fuzzylink/llms.txt Illustrates the `check_match` function for determining if two strings refer to the same entity using LLMs. It supports single pair and vectorized comparisons, custom record types, instructions, and various LLM providers like Anthropic Claude and Mistral. ```r library(fuzzylink) # Single pair comparison check_match('UPS', 'United Parcel Service') #> [1] "Yes" check_match('UPS', 'United States Postal Service') #> [1] "No" # Vectorized comparison check_match( c('USPS', 'USPS', 'USPS'), c('Post Office', 'United Parcel', 'US Postal Service') ) #> [1] "Yes" "No" "Yes" # With custom record type and instructions check_match( 'Microsoft Corp', 'MSFT', record_type = 'company', instructions = 'Consider stock ticker symbols as valid identifiers.' ) #> [1] "Yes" # Using Anthropic Claude model check_match( c('NYC', 'LA', 'SF'), c('New York City', 'Los Angeles', 'San Francisco'), model = 'claude-sonnet-4-5-20250929', record_type = 'city' ) #> [1] "Yes" "Yes" "Yes" # Using Mistral model check_match( 'J.K. Rowling', 'Joanne Rowling', model = 'mistral-large-latest', record_type = 'author' ) #> [1] "Yes" ``` -------------------------------- ### Fuzzy Linking Dataframes in R Source: https://github.com/joeornstein/fuzzylink/blob/main/README.md This R code snippet demonstrates fuzzy linking between two dataframes (dfA and dfB) using the 'fuzzylink' package. It defines sample data, applies the 'fuzzylink' function with specified columns and record type, and prints the resulting linked dataframe. Dependencies include 'tidyverse' and 'fuzzylink'. ```r library(tidyverse) library(fuzzylink) dfA <- tribble(~name, ~age, 'Joe Biden', 81, 'Donald Trump', 77, 'Barack Obama', 62, 'George W. Bush', 77, 'Bill Clinton', 77) dfB <- tribble(~name, ~hobby, 'Joseph Robinette Biden', 'Football', 'Donald John Trump ', 'Golf', 'Barack Hussein Obama', 'Basketball', 'George Walker Bush', 'Reading', 'William Jefferson Clinton', 'Saxophone', 'George Herbert Walker Bush', 'Skydiving', 'Biff Tannen', 'Bullying', 'Joe Riley', 'Jogging') df <- fuzzylink(dfA, dfB, by = 'name', record_type = 'person') df ``` -------------------------------- ### Compute Dot Product (Cosine Similarity) Source: https://context7.com/joeornstein/fuzzylink/llms.txt Computes the dot product between two numeric vectors, which corresponds to cosine similarity for normalized embeddings. This is useful for comparing individual embedding vectors to determine their semantic relatedness. ```r library(fuzzylink) # Basic dot product dot(c(1, 0, 0), c(1, 0, 0)) #> [1] 1 dot(c(1, 0, 0), c(0, 1, 0)) #> [1] 0 dot(c(0.5, 0.5, 0), c(0.5, 0.5, 0)) #> [1] 0.5 # With embeddings embeddings <- get_embeddings(c('machine learning', 'deep learning', 'cooking recipes')) # High similarity between related concepts dot(embeddings['machine learning',], embeddings['deep learning',]) #> [1] 0.9234567 # Low similarity between unrelated concepts dot(embeddings['machine learning',], embeddings['cooking recipes',]) #> [1] 0.2345678 ``` -------------------------------- ### Compute Similarity Matrix for Subsets Source: https://context7.com/joeornstein/fuzzylink/llms.txt Calculates the similarity matrix between specified subsets of strings using pre-computed embeddings. This function is useful for comparing a single string against multiple others or two sets of strings against each other. ```r sim_subset <- get_similarity_matrix( embeddings, strings_A = 'Postal Service', strings_B = c('UPS', 'USPS', 'FedEx') ) sim_subset #> UPS USPS FedEx #> Postal Service 0.5678901 0.8901234 0.4321098 sim_ab <- get_similarity_matrix( embeddings, strings_A = c('UPS', 'FedEx'), strings_B = c('United Parcel', 'Postal Service') ) sim_ab #> United Parcel Postal Service #> UPS 0.9012345 0.5678901 #> FedEx 0.5123456 0.4321098 ``` -------------------------------- ### Perform Record Linkage with fuzzylink() in R Source: https://github.com/joeornstein/fuzzylink/blob/main/README.md This function performs probabilistic record linkage between two dataframes (dfA and dfB) based on a specified key variable ('name' in this case) and record type ('person'). It utilizes pretrained text embeddings to calculate similarity measures and estimates the probability of a match. ```r library(fuzzylink) df <- fuzzylink(dfA, dfB, by = 'name', record_type = 'person') df ``` -------------------------------- ### Perform Probabilistic Record Linkage Source: https://context7.com/joeornstein/fuzzylink/llms.txt The fuzzylink function merges two data frames by identifying matches based on semantic similarity of specified variables. It utilizes embeddings and LLM validation to return a combined dataset with match probability scores. ```r library(fuzzylink) library(tidyverse) dfA <- tribble(~name, ~age, 'Joe Biden', 81, 'Donald Trump', 77) dfB <- tribble(~name, ~hobby, 'Joseph Robinette Biden', 'Football', 'Donald John Trump', 'Golf') # Perform fuzzy matching df <- fuzzylink(dfA, dfB, by = 'name', record_type = 'person') print(df) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.