@@ -44,25 +44,27 @@ public static List<EmbeddingManager.SimilarityResult> findRelevantDocuments(Stri
4444
4545 // Generate embedding for the query
4646 System .out .println ("Generating embedding for query" );
47- Vector < Double > queryEmbedding = manager .generateQueryEmbedding (query );
47+ double [] queryEmbedding = manager .generateQueryEmbedding (query );
4848 if (queryEmbedding == null ) {
4949 System .err .println ("Error: Failed to generate query embedding" );
5050 throw new ApplicationException ("Failed to generate query embedding" );
5151 }
52- System .out .println ("Generated query embedding with dimension: " + queryEmbedding .size () );
52+ System .out .println ("Generated query embedding with dimension: " + queryEmbedding .length );
5353
5454 // Find similar documents - get more results than needed to ensure diversity
5555 System .out .println ("Finding similar documents" );
5656 int initialResultsCount = maxResults * 3 ; // Get 3x more results initially
57- List <EmbeddingManager .SimilarityResult > allResults = EmbeddingManager .findSimilar (queryEmbedding , initialResultsCount );
57+ List <EmbeddingManager .SimilarityResult > allResults = EmbeddingManager .findSimilar (queryEmbedding ,
58+ initialResultsCount );
5859 System .out .println ("Found " + allResults .size () + " similar documents" );
5960
6061 // Filter by similarity threshold
6162 List <EmbeddingManager .SimilarityResult > filteredResults = allResults .stream ()
6263 .filter (result -> result .similarity >= SIMILARITY_THRESHOLD )
6364 .collect (Collectors .toList ());
6465
65- System .out .println ("Filtered to " + filteredResults .size () + " documents with similarity >= " + SIMILARITY_THRESHOLD );
66+ System .out .println (
67+ "Filtered to " + filteredResults .size () + " documents with similarity >= " + SIMILARITY_THRESHOLD );
6668 return filteredResults ;
6769 } catch (Exception e ) {
6870 System .err .println ("Error finding relevant documents: " + e .getMessage ());
@@ -84,6 +86,7 @@ public static List<EmbeddingManager.SimilarityResult> findRelevantDocuments(Stri
8486
8587 /**
8688 * Format document fragments as context for a language model
89+ *
8790 * @param results List of document fragments with similarity scores
8891 * @return Formatted context string
8992 */
@@ -115,10 +118,10 @@ public static String formatDocumentsAsContext(List<EmbeddingManager.SimilarityRe
115118 // Create document entry
116119 StringBuilder documentEntry = new StringBuilder ();
117120 documentEntry .append ("Document " ).append (i + 1 )
118- .append (" (Title: " ).append (title )
119- .append (", File: " ).append (fileName )
120- .append (", Relevance: " ).append (String .format ("%.2f" , result .similarity ))
121- .append ("):\n " );
121+ .append (" (Title: " ).append (title )
122+ .append (", File: " ).append (fileName )
123+ .append (", Relevance: " ).append (String .format ("%.2f" , result .similarity ))
124+ .append ("):\n " );
122125 documentEntry .append (content ).append ("\n \n " );
123126
124127 // Check if adding this document would exceed the maximum context length
@@ -137,7 +140,7 @@ public static String formatDocumentsAsContext(List<EmbeddingManager.SimilarityRe
137140 // Add a note about how many documents were found vs. included
138141 if (documentsAdded < results .size ()) {
139142 context .append ("Note: Found " + results .size () + " relevant documents, but only included " +
140- documentsAdded + " to stay within context limits.\n \n " );
143+ documentsAdded + " to stay within context limits.\n \n " );
141144 }
142145
143146 return context .toString ();
@@ -147,7 +150,8 @@ public static String formatDocumentsAsContext(List<EmbeddingManager.SimilarityRe
147150 * Enhance a user query with relevant document fragments
148151 *
149152 * @param query The original user query
150- * @return Enhanced query with document context, or the original query if no relevant documents found
153+ * @return Enhanced query with document context, or the original query if no
154+ * relevant documents found
151155 */
152156 public static String enhanceQueryWithDocuments (String query ) throws ApplicationException {
153157 try {
@@ -176,7 +180,7 @@ public static String enhanceQueryWithDocuments(String query) throws ApplicationE
176180 * @return True if document context was added, false otherwise
177181 */
178182 public static boolean addDocumentContextToMessages (String query , String meetingCode ,
179- Builders messages ) throws ApplicationException {
183+ Builders messages ) throws ApplicationException {
180184 try {
181185 System .out .println ("Finding relevant documents for query: " + query );
182186 List <EmbeddingManager .SimilarityResult > relevantDocs = findRelevantDocuments (query );
@@ -209,21 +213,23 @@ public static boolean addDocumentContextToMessages(String query, String meetingC
209213
210214 if (context .length () > maxSafeCharLimit ) {
211215 System .out .println ("Warning: Context exceeds safe token limit. Truncating from " +
212- context .length () + " to " + maxSafeCharLimit + " characters" );
216+ context .length () + " to " + maxSafeCharLimit + " characters" );
213217 formattedContext = context .substring (0 , maxSafeCharLimit );
214218 }
215219
216220 // Add system message with document context
217221 Builder contextMessage = new Builder ();
218222 contextMessage .put ("role" , "system" );
219- contextMessage .put ("content" , "I am providing you with some relevant document fragments to help answer the user's question. " +
220- "These documents are highly relevant to the current conversation context. " +
221- "Instructions for using this information:\n " +
222- "1. Prioritize this information over your general knowledge when answering\n " +
223- "2. Cite the specific document title/number when using information from it\n " +
224- "3. If multiple documents contain relevant information, synthesize it\n " +
225- "4. If the documents don't contain the answer, clearly state that and use your general knowledge\n " +
226- "5. Maintain continuity with the previous conversation\n \n " + formattedContext );
223+ contextMessage .put ("content" ,
224+ "I am providing you with some relevant document fragments to help answer the user's question. " +
225+ "These documents are highly relevant to the current conversation context. " +
226+ "Instructions for using this information:\n " +
227+ "1. Prioritize this information over your general knowledge when answering\n " +
228+ "2. Cite the specific document title/number when using information from it\n " +
229+ "3. If multiple documents contain relevant information, synthesize it\n " +
230+ "4. If the documents don't contain the answer, clearly state that and use your general knowledge\n "
231+ +
232+ "5. Maintain continuity with the previous conversation\n \n " + formattedContext );
227233 messages .add (contextMessage );
228234
229235 System .out .println ("Added document context to messages" );
0 commit comments