Overview • How it works • Development
fhb-assistant.mp4
FHB Assistant is loaded with up to date, context specific information to provide general guidance on all government schemes, the complexity of australian home loans and the purchasing process involved.
FBH Assistant uses retrieval augmented generation (RAG), which is just a fancy term for the manipulation of prompts to provide relevant information to an LLM when a question is asked. An LLM will (hopefully) hallucinate less if the answer to the user's question is presented to it in the same prompt as the question.
- Documents containing context relevant information are split into smaller overlapping chunks of text
- Each chunk is vectorised via an embeddings model which returns an n dimensional vector representing a text chunk's position in space relative to all other chunks containing similar content in meaning
- The embeddings for 'boat' and 'sail' would be close together but 'boat' and 'refrigerator' would be further apart.
- Store the embeddings in a database
- When a user asks a question, generate an embedding vector for the question text
- Look up the top x closest text chunks to the question from the database using a distance function e.g. cosine distance
- Prepend the user's question with the context from the text chunks and send it to an LLM
- The LLM will answer the question based on the context provided, providing answers based on content from the original documents
Some intermediate prompt refinement steps used to increase output quality, for example:
- contextualising a user prompt based on the chat history and,
- performing multiple LLM passes on the text content to extract only the relevant information.
There is no guarantee of the correctness of responses because hallucinations are unavoidable!
- Copy the .env.example file to .env and fill in the required fields
cp .env.example .env
- Install dependencies and build
npm i && npm run build
- Start the pg-vector docker container, generate and apply a migration
npm run docker npm run db:migrate-generate npm run db:migrate-apply
- Start the server
npm run dev
- Edit documents in the config file
- Run the document seed script
npm run seed-content