-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract common code for ES and OS into a base class #2664
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I have two questions regarding ElasticsearchCommon, nothing blocking though 🙂
return hosts | ||
|
||
|
||
class ElasticsearchCommon(KeywordDocumentStore): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small issues here:
-
I think this should be an abstract class, because it's not meant to be implemented. It has no abstract methods for now, but I imagine it will once you move to the final hierarchy that you designed in the PR description. So if this is meant to be temporary we can make this abstract later.
-
I'm not too fond of the name. We use to prefix these base abstract classes with
Base
, so if I had to follow the pattern, this would be calledBaseElasticsearchDocumentStore
or anywayBase[Something]DocumentStore
. The currentElasticsearchCommon
is way too generic imho, doesn't imply anywhere we're even talking about a docstore. If this objection sounds too far-fetched, be aware that until very short ago we had anElasticsearchRetriever
, soElasticsearchCommon
sounds like a set of functions that could serve both, which is not correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think this should be an abstract class,
I tried, but in the end we don't need abstract methods here, and adding one just for the sake of make the class not instantiable is wrong IMO. I think good documentation and clean code is enough in Pythonland, but If this is important, I'd rather raise an error in the __new__
method of the class
I'm not too fond of the name.
Me too, it's pretty bad and this is a code smell - a class hierarchy isn't probably the right tool here, but this is way off topic 😅. I'll change it to BaseElasticsearchDocumentStore
.
Anyways, you touch an interesting point here:
If this objection sounds too far-fetched, be aware that until very short ago we had an ElasticsearchRetriever, so ElasticsearchCommon sounds like a set of functions that could serve both, which is not correct.
I disagree - when thinking about names we should take into consideration the fully qualified name: ElasticsearchCommon
alone is obviously bad, but its name is actually haystack.document_stores.elasticsearch. ElasticsearchCommon
. It's not unusual to leverage fully qualified names in API design: for example, in Django you have a class named DatabaseWrapper
in every backend instead of MysqlWrapper
, PostgresqlWrapper
and so on. Not something I would necessarily add to Haystack, just wanted to mention that packages and modules should be used to provide namespacing when writing Python APIs, as opposed to put all the effort in function or class names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the abstract class, I agree that if we have to do workarounds to make it really abstract then it's worthless. +1 for keeping it as it is.
For the name, nice idea! I still think it's better to use BaseElasticsearchDocumentStore
here and I'm glad we agree, but I'll keep it in mind for other situations. Sounds like a handy solution to keep names short.
* extract common code for ES and OS into a base class * Update Documentation & Code Style * give the base class a more obvious name * Update Documentation & Code Style Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Related issue: #1764
Proposed changes:
ElasticsearchCommon
implementing the code that Elasticsearch and Opensearch have in common at this momentElasticsearchDocumentStore
implementing the same type as beforeBefore
After
Next step (upcoming PR)
Status (please check what you already did):