Balancing Predefined and User-Generated Topics in Suggestion Systems
Sep 8, 2024
134 views
Written by Prashant Basnet
👋 Welcome to my Signature, a space between logic and curiosity.
I’m a Software Development Engineer who loves turning ideas into systems that work beautifully.
This space captures the process: the bugs, breakthroughs, and “aha” moments that keep me building.
Current topic suggestion architecture:
Trie reflects only following data:
How is this trie data structure created, when?
Currently this trie can be created using an api.
The important part is: Once the trie is created, it will only reflect all the topics/data that is in the system by the time generation.
For example: we give following data and create a trie.
now this is our current trie:
A user creates a new space called business. Note that our trie is already generated.
Then that latter space will note be reflected in the topics trie. Since, we created this space after we created our trie, the trie will not reflect the newly added topic of business. And so when user searches business in topics, it will not show up in the search.
In this example, 3 topics i.e computer science, maths, and data science will be sent as payload, whereas the Deep learning is not found as shown in the picture. Thus will not reflected in payload to thread creation api.
**** important ****
Currently new topics cannot be created by adding new topics.
Let's see how our code of trie is:
const { sortWith, descend, prop } = require("ramda"); function TrieNode(value) { return { char: value, isEnd: false, keys: {}, entityType: null, // 'major' or 'school' unitId: null, pictures: null, alias: null, universityCount: 0, _id: null, }; } class Trie { constructor() { this.root = { root: true, keys: {}, }; } insert(word, entityType, data, node = this.root) { if (word.length === 0) { node.isEnd = true; node.entityType = entityType; node.unitId = data.unitId; node.pictures = data.pictures; node.alias = data.alias; node.universityCount = data.universityCount || 0; node._id = data._id; node.type = data.type; } else if (!node.keys[word[0]]) { node.keys[word[0]] = TrieNode(word[0]); this.insert(word.substring(1), entityType, data, node.keys[word[0]]); } else { this.insert(word.substring(1), entityType, data, node.keys[word[0]]); } } search(word, node = this.root) { if (word.length === 0) { return node.isEnd; } else if (node.keys[word[0]]) { return this.search(word.substring(1), node.keys[word[0]]); } else if (!node.keys[word[0]]) { node.keys[word[0]] = TrieNode(word[0]); return this.search(word.substring(1), node.keys[word[0]]); } } myTree() { return this.root; } }We then insert all the different sort of datas into our trie tree. which will look like this:
For majors:
Now, these 5 majors are predefined in the trie system.
now if we want to search for business, then we'd not find any suggestion for that. This is the current problem.
How to add anything that is not already predefined.
How can we refine our topic suggestion algorithm to pick user suggested first time topics?
Few things we can brainstorm:
Challenges:
we will continue this thread discussion in our updated trie system.