Add New `SemanticResolver` component
Is your feature request related to a problem? Please describe.
When generating your own knowledge graph using LLMs, the LLMMetadataExtractor component can be used to encode entities and relationships inside the metadata of haystack Document objects. LLMMetadataExtractor supports ChatGenerator's that could use structured output to define possible graph ontology, however it is common when creating knowledge to not have predefined possible entities, especially when working with large amounts of data.
This means you can have generated metadata for document_one and document_two such that;
document_one.meta = {'entities': [{'entity': 'deepset', 'entity_type': 'company'}]}
document_two.meta = {'entities': [{'entity': 'deepset GmbH', 'entity_type': 'company'}]}
when these entities are referring to the same concept. These entities are often ingested into a graph as separate nodes.
Describe the solution you'd like
Implement a new SemanticResolver component that uses the text-embedding-inference (TEI) similarity endpoint along with a given threshold to determine whether entities are similar enough to merge and then merges the entities.
Describe alternatives you've considered
Using spaCy to determine similarity, however this is much slower than TEI. However, another component could be created that utilises spaCy.
Additional context Add any other context or screenshots about the feature request here.
Hi @julian-risch , I'd like to pick this up!
I've been looking into the implementation. My plan is to create a SemanticResolver component in haystack/components/preprocessors/ that uses the TEI /similarity endpoint.
I'm planning to use a clustering approach where entities with a similarity above the threshold are merged under a canonical name.
Does this approach sound right to you? If so, please assign this to me!
Hi @julian-risch and @maxdswain,
Following up on my earlier note: I have prepared an implementation of SemanticResolver on my fork with TEI /similarity batching, Union-Find clustering, multiple canonicalization strategies, non-destructive metadata preservation, and 30 unit tests covering edge cases.
I wanted to double-check if @ritikraj2425 is currently working on this. If not, I would be very happy to submit a pull request with the implementation, tests, and documentation for review!
Hi, I'd also be interested in working on this one. @ritikraj2425 @tech00exploere, are either of you still on it? @tech00exploere it sounds like you're already well ahead with the implementation, so if you're planning to open the PR I'm happy to step back. If it's free, I'd start with the TEI /similarity batching and clustering, and keep the first PR small with tests.
thanks @tharunsridhar! yes, I have the implementation, unit tests, and documentation ready on my branch. I'm opening the pr right now so everyone can review. really appreciate you checking in and coordinating!