## 3 Proposed Method
### Adaptable Behavioural Layer
#### 3.3.2 Vector Database Implementation  
The vector database is implemented with the help of FAISS [107] to search for similar vectors in high-dimensional space. Word vectors are created using the \"all-MiniLM-L6-v2\" model [106], a fast and efficient transformer model, which is stored in the vector index for efficient search. The FAISS index is specifically designed for large-scale document search, so the system can easily maintain high accuracy and low latency in document retrieval irrespective of the amount of data being added. This indexing and retrieval mechanism guarantees that the model can use the most relevant information during inference and thereby improve the overall decision-making and flexibility in dynamic scenarios.  
We use a single vector database for context retrieval and its potential impact on scalability as dataset volume and diversity grow. To mitigate this, future implementations could employ distributed or hierarchical indexing techniques, which divide data across multiple indices or layers based on relevance or category. These techniques allow scalable expansion by segmenting data retrieval processes, which improves search efficiency without compromising retrieval accuracy. By adopting these advanced indexing methods, the system can handle larger, more heterogeneous datasets while maintaining low latency and high accuracy.  
**Require:** Query \(q\), Document corpus \(D\), Vector database \(V\), Fine-tuned language models {Llama-2, Llama-3, GPT-3.5 Turbo, GPT-4o Mini}  
**Ensure:** Final sentiment classification output \(S\)  
```
1:Step 1:Query Embedding Creation
2:Encode the input query \(q\) into an embedding \(\mathbf{q}\) using the pre-trained embedding model (e.g., 'all-MiniLM-L6-v2')
3:Step 2:Vector Database Retrieval (FAISS)
4:Use FAISS to retrieve the top-\(k\) relevant document embeddings \(\{d_{1},d_{2},\ldots,d_{k}\}\) from \(V\) based on the Euclidean distance between \(\mathbf{q}\) and each document embedding \(\mathbf{v}_{i}\) in \(V\): \[d(\mathbf{q},\mathbf{v}_{i})=\|\mathbf{q}-\mathbf{v}_{i}\|_{2}\] (5)
5:Step 3:RAG
6:for each retrieved document \(d_{i}\) in \(\{d_{1},d_{2},\ldots,d_{k}\}\)do
7: Concatenate \(q\) with \(d_{i}\) to form a combined input
8: Pass the combined input to each fine-tuned language model to generate an intermediate response \(r_{i}\) with probability: \[P(r\mid q)=\sum_{d\in D_{k}}P(r\mid q,d)P(d\mid q)\] (6)
9:Step 4:Fine-Tuning with Domain-Specific Data
10:for each model \(M\) in {Llama-2, Llama-3, GPT-3.5 Turbo, GPT-4o Mini} do
11: Fine-tune \(M\) on financial review data, using techniques such as LoRA and 4-bit quantisation for efficient adaptation
12: Update model parameters with optimised hyper-parameters (learning rate, batch size, gradient accumulation) as needed
13:Step 5: Sentiment Response Generation
14:for each model \(M\) in {Llama-2, Llama-3, GPT-3.5 Turbo, GPT-4o Mini} do
15: Generate a sentiment classification output \(S_{i}\) for the query \(q\) using model \(M\)
16:Step 6: Ensemble Voting for Final Output
17: Combine the outputs \(\{S_{1},S_{2},S_{3},S_{4}\}\) from each model using majority voting to determine the final sentiment classification \(S\)
18:return\(S\)
```  
**Algorithm 4** Adaptable Behavioural Layer