Class: Forem::Services::ConceptService
- Inherits:
-
BaseService
- Object
- BaseService
- Forem::Services::ConceptService
- Defined in:
- lib/forem/services/concept_service.rb
Overview
Service for interacting with the Forem Concepts API.
Concepts are semantic, ML-generated categories: articles are classified under a concept when their embedding is close enough to the concept's anchor embedding. This service covers the public concept endpoints (+/api/concepts+); creating and deleting concepts is an admin-only operation exposed by AdminConceptService.
Access via Client#concepts. All methods inject the client's requestor automatically so no additional configuration is required.
Instance Method Summary collapse
-
#articles(id, params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
List the published articles classified under a concept.
-
#list(params = {}, opts = {}) ⇒ Forem::ListObject<Concept>
List the concepts accessible to the authenticated user.
-
#retrieve(id, params = {}, opts = {}) ⇒ Concept
Retrieve a single concept by its numeric ID.
-
#search(params = {}, opts = {}) ⇒ Array<Concept>
Semantically search the concepts accessible to the caller.
-
#update(id, params = {}, opts = {}) ⇒ Concept
Update an existing concept.
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from Forem::Services::BaseService
Instance Method Details
#articles(id, params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
List the published articles classified under a concept.
Articles are ordered by semantic distance (closest first) with the
article score as a tiebreaker, unless sort is "score".
114 115 116 |
# File 'lib/forem/services/concept_service.rb', line 114 def articles(id, params = {}, opts = {}) Concept.articles(id, params, opts_with_requestor(opts)) end |
#list(params = {}, opts = {}) ⇒ Forem::ListObject<Concept>
List the concepts accessible to the authenticated user.
Super admins see every concept; other users see only the concepts
they have been granted access to. Each concept includes nested
daily_metrics covering the last days days, newest first.
42 43 44 |
# File 'lib/forem/services/concept_service.rb', line 42 def list(params = {}, opts = {}) Concept.list(params, opts_with_requestor(opts)) end |
#retrieve(id, params = {}, opts = {}) ⇒ Concept
Retrieve a single concept by its numeric ID.
The response includes nested daily_metrics for the last days days
and a top_articles array with the concept's three highest-scoring
articles.
64 65 66 |
# File 'lib/forem/services/concept_service.rb', line 64 def retrieve(id, params = {}, opts = {}) Concept.retrieve(id, params, opts_with_requestor(opts)) end |
#search(params = {}, opts = {}) ⇒ Array<Concept>
Semantically search the concepts accessible to the caller.
The query is embedded and compared against each concept's anchor
embedding. Results come back closest-first, each with distance and
similarity alongside the usual concept fields. This endpoint
requires an API key and is not paginated.
138 139 140 |
# File 'lib/forem/services/concept_service.rb', line 138 def search(params = {}, opts = {}) Concept.search(params, opts_with_requestor(opts)) end |
#update(id, params = {}, opts = {}) ⇒ Concept
Update an existing concept.
Params are wrapped in the concept key expected by the API, so they
can be passed flat. Only score, description, and
similarity_threshold are permitted. Updating the description
regenerates the concept's anchor embedding; updating the description
or the similarity threshold re-classifies existing articles in the
background.
91 92 93 |
# File 'lib/forem/services/concept_service.rb', line 91 def update(id, params = {}, opts = {}) Concept.update(id, params, opts_with_requestor(opts)) end |