Class HibernateContentRetriever.HibernateContentRetrieverBuilder
java.lang.Object
dev.langchain4j.rag.content.retriever.hibernate.HibernateContentRetriever.HibernateContentRetrieverBuilder
- Enclosing class:
HibernateContentRetriever
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds a newHibernateContentRetrieverinstance with the configured parameters.Sets theChatModelto be used for generating HQL queries from natural language.databaseStructure(String databaseStructure) Sets the structure of the entity model, which will be provided to the LLM in the system message.entityManagerFactory(jakarta.persistence.EntityManagerFactory entityManagerFactory) Sets theEntityManagerFactoryto be used for executing HQL queries and extracting the metamodel.maxRetries(Integer maxRetries) Sets the maximum number of retries to perform if Hibernate cannot execute the generated HQL query.promptTemplate(PromptTemplate promptTemplate) Sets thePromptTemplateto be used for creating the system message.sessionFactory(org.hibernate.SessionFactory sessionFactory) Sets theSessionFactoryto be used for executing HQL queries and extracting the metamodel.toString()
-
Method Details
-
sessionFactory
public HibernateContentRetriever.HibernateContentRetrieverBuilder sessionFactory(org.hibernate.SessionFactory sessionFactory) Sets theSessionFactoryto be used for executing HQL queries and extracting the metamodel. This is a mandatory parameter (either this orentityManagerFactory(EntityManagerFactory)must be set).- Parameters:
sessionFactory- the HibernateSessionFactory- Returns:
- this builder
-
entityManagerFactory
public HibernateContentRetriever.HibernateContentRetrieverBuilder entityManagerFactory(jakarta.persistence.EntityManagerFactory entityManagerFactory) Sets theEntityManagerFactoryto be used for executing HQL queries and extracting the metamodel. The providedEntityManagerFactorywill be unwrapped to a HibernateSessionFactory. This is a mandatory parameter (either this orsessionFactory(SessionFactory)must be set).- Parameters:
entityManagerFactory- the Jakarta PersistenceEntityManagerFactory- Returns:
- this builder
-
chatModel
-
databaseStructure
public HibernateContentRetriever.HibernateContentRetrieverBuilder databaseStructure(String databaseStructure) Sets the structure of the entity model, which will be provided to the LLM in the system message. The LLM should be familiar with available entities, attributes, relationships, etc. in order to generate valid HQL queries. This is an optional parameter. If not specified, it will be automatically generated from theSessionFactory's runtime metamodel (recommended).- Parameters:
databaseStructure- a string representation of the entity model structure- Returns:
- this builder
-
promptTemplate
public HibernateContentRetriever.HibernateContentRetrieverBuilder promptTemplate(PromptTemplate promptTemplate) Sets thePromptTemplateto be used for creating the system message. The template can use the{{databaseStructure}}variable, which will be replaced with the entity model structure. This is an optional parameter. Default:HibernateContentRetriever.DEFAULT_PROMPT_TEMPLATE.- Parameters:
promptTemplate- thePromptTemplateto use- Returns:
- this builder
-
maxRetries
Sets the maximum number of retries to perform if Hibernate cannot execute the generated HQL query. On each retry, the error message will be sent back to the LLM to try correcting the query. This is an optional parameter. Default: 0.- Parameters:
maxRetries- the maximum number of retries- Returns:
- this builder
-
build
Builds a newHibernateContentRetrieverinstance with the configured parameters.- Returns:
- a new
HibernateContentRetriever
-
toString
-