Spaces:
Running
Running
Update rag_pipeline.py
Browse files- 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
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
)
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = []
|