A content-based recommender suggests entities by matching their attributes. On a job site, it can compare a user’s profile with job titles, skills, industries, salary ranges, and experience requirements, then rank matching jobs. The same approach can find items similar to an item a user already likes. section 9.2.1
The entities being compared can be users or items. For example, product recommendations can use category and description text, or other attributes such as brand, color, and size. The choice of features matters: an attribute that looks similar in the data may not be important to users. section 9.2.1 section 4.1.1
Related laundry products
After a user views detergent, a recommender can suggest fabric softener and dryer sheets because they share a laundry category and have similar product-description text. section 9.2.1
For document recommendations, a semantic knowledge graph can turn the starting document into a search query. It scores document terms against a known topic, selects the most related terms, and uses them to find other documents with similar content. section 5.4.6 section 5.6
A document-to-query pipeline can proceed as follows:
- Extract phrases from the document and traverse the graph to score their relatedness to its classification. section 5.4.6
- Filter the scored phrases and build a query that boosts each retained phrase by its relatedness score. In the example, the cutoff is greater than 0.25. section 5.4.6
- Search the title and body fields with the resulting query and return the highest-ranked documents. section 5.4.6
Listing 5.9 Generating a recommendation query from scored phrases
def get_scored_terms(traversal):
return {term: data["relatedness"]
for term, data in traversal["graph"][0]["values"]["star wars"] \
["traversals"][0]["values"].items()}
rec_query = " ".join(f'"{term}"^{score}'
for term, score in get_scored_terms(traversal).items()
if score > 0.25)
print(f"Expanded Query:\n{rec_query}")
This Python listing filters scored phrases and joins them into a boosted recommendation query. section 5.4.6
Listing 5.10 Running the content-based recommendations query
stackexchange_collection = engine.get_collection("stackexchange")
request = {"query": rec_query,
"query_fields": ["title", "body"],
"return_fields": ["title"],
"limit": 5,
"filters": [("title", "*")]}
response = stackexchange_collection.search(**request)
print(json.dumps(response["docs"], indent=2))
This search request runs the query against document titles and bodies, returning up to five titles. section 5.4.6
Content matching can work when there are too few behavioral signals for collaborative filtering, but it does not by itself capture users’ preferences. A hybrid recommender can use content matching as a baseline and give collaborative filtering greater prominence when sufficient interactions are available. Signals have their own limitation: recommendations can become self-reinforcing when interactions follow prior recommendations. section 4.1.1 section 9.2.3



