KhwaishK commited on
Commit
91ce8b7
·
verified ·
1 Parent(s): fb23f40

Update rag_pipeline.py

Browse files
Files changed (1) hide show
  1. rag_pipeline.py +12 -7
rag_pipeline.py CHANGED
@@ -5,13 +5,18 @@ from embedding_functions import embed_text
5
 
6
  llm = ChatGroq(model="meta-llama/llama-4-scout-17b-16e-instruct")
7
 
8
- def retrieve_multimodal(query, vector_store, k=5):
9
- query_embedding = embed_text(query)
10
- results = vector_store.similarity_search_by_vector(
11
- embedding = query_embedding,
12
- k = k
13
- )
14
- return results
 
 
 
 
 
15
 
16
  def create_multimodal_message(query, retrieved_docs, image_data_store):
17
  content = []
 
5
 
6
  llm = ChatGroq(model="meta-llama/llama-4-scout-17b-16e-instruct")
7
 
8
+ def retrieve_multimodal(query, vector_store):
9
+ # 1. Cast a much wider net so images don't get pushed out by text scores
10
+ all_results = vector_store.similarity_search(query=query, k=20)
11
+
12
+ # 2. Separate the results manually
13
+ text_docs = [doc for doc in all_results if doc.metadata.get("type") == "text"]
14
+ image_docs = [doc for doc in all_results if doc.metadata.get("type") == "image"]
15
+
16
+ # 3. Guarantee that we return the top 5 texts AND the top 2 images
17
+ final_docs = text_docs[:5] + image_docs[:2]
18
+
19
+ return final_docs
20
 
21
  def create_multimodal_message(query, retrieved_docs, image_data_store):
22
  content = []