## 3 Proposed Method
### Preprocessing Layer
#### 3.2.4 Conversion and Embedding  
After data cleaning and preprocessing, the data are transformed into numerical representations that are called embeddings. These embeddings are obtained using the Sentence-Transformer model known as _all-MiniLM-L6-v2_[106]. The model aims at capturing the semantic meaning of the text so that vectors that represent similar sentiments are close in this high-dimensional space. The values of the embedding dimension for each document are 384. The generated embeddings are then saved in a Facebook AI Similarity Search (FAISS) index [107] for efficient search.  
The embeddings are derived in the following manner. Here, let \(X=\{x_{1},x_{2},\ldots,x_{n}\}\) be the cleaned and preprocessed set of reviews, where each \(x_{1}\) is a textual input. The embedding model \(\phi\) transforms each \(x_{i}\) into a fixed-size vector \(\mathbf{v}_{i}\in\mathbb{R}^{384}\):  
\[\mathbf{v}_{i}=\phi(x_{i}), \tag{3}\]  
where \(\mathbf{v}_{i}\) is the embedding vector for review \(x_{i}\).  
The FAISS index is used to index the embedding vectors. Given a query vector \(\mathbf{q}\), the retrieval process finds the \(k\) nearest neighbours by minimising the Euclidean distance \(d\) between \(\mathbf{q}\) and all stored vectors \(\mathbf{v}_{i}\):  
\[d(\mathbf{q},\mathbf{v}_{i})=\|\mathbf{q}-\mathbf{v}_{i}\|_{2}. \tag{4}\]  
The algorithm returns the \(k\) documents with the smallest distance \(d\), indicating the text with the most semantically similar reviews. This embedding and retrieval approach allows the sentiment analysis model to be both scalable and capable of delivering high-quality results by adding contextual and semantic information to the input data.  
Generation and document retrieval are critical processes in gathering the most relevant context for sentiment analysis. Pre-trained embedding models and FAISS [107] are used to efficiently index documents. The embedding generation stage converts both the query and the documents into dense vectors, obtaining the semantic information required to perform similarity matching. The document retrieval procedure then uses FAISS to discover the documents most comparable to the vector representations by performing a nearest-neighbour search on the top \(k\) results. Algorithm 3 provides a step-by-step overview of the entire process, from embedding generation to retrieval.  
Figure 4: Reason and Act with OpenAI GPT-3.5 Turbo Model.  
```
0: Query \(q\), Document Set \(X=\{x_{1},x_{2},\dots,x_{n}\}\), Number of neighbours \(k\)
0: Top \(k\) most relevant documents \(D_{\text{top}_{k}}\)
1: Load pre-trained embedding model \(\phi\)
2: Initialise FAISS index \(I\)
3: Initialise index-to-document map \(M\)
4:for each document \(x_{i}\) in \(X\)do
5:\(v_{i}\leftarrow\phi(x_{i})\)\(\triangleright\) Generate embedding for document \(x_{i}\)
6: Add \(v_{i}\) to FAISS index \(I\)
7:\(M[i]\gets x_{i}\)\(\triangleright\) Store document reference for later retrieval
8:\(q_{\text{embedding}}\leftarrow\phi(q)\)\(\triangleright\) Generate embedding for the query
9:\([d_{\text{top}_{k}},\text{indices}]\gets I.\text{search}(q_{\text{embedding}},k)\)\(\triangleright\) Retrieve top \(k\) nearest neighbours
10:\(D_{\text{top}_{k}}\leftarrow\{M[\text{indices}[j]]\mid j=1,\dots,k\}\)\(\triangleright\) Map retrieved indices back to original documents
11:return\(D_{\text{top}_{k}}\)
```  
**Algorithm 3** Conversion and Embedding Generation