seansullivan commited on
Commit
7555b41
·
verified ·
1 Parent(s): 5489ec4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -42,9 +42,12 @@ pc = Pinecone(api_key=PINE_API_KEY)
42
  index = pc.Index(index_name)
43
 
44
  # ========== PART 3 ==========
 
 
 
45
  splade_encoder = SpladeEncoder()
46
  retriever = PineconeHybridSearchRetriever(
47
- embeddings=embed, sparse_encoder=splade_encoder, index=index
48
  )
49
 
50
 
@@ -95,8 +98,8 @@ class PassParentContent(Runnable):
95
 
96
  rag_chain = (
97
  RunnablePassthrough()
98
- # | SourceDedup()
99
- # | PassParentContent()
100
  | prompt
101
  | model
102
  | StrOutputParser()
@@ -120,20 +123,20 @@ def generate_response(prompt):
120
  elif list(chunk.keys())[0] == 'context':
121
  pass
122
  # Sources DO NOT work the same with this code... removing for now.
123
- # sources = chunk['context']
124
- #for thing in chunk['context']:
125
- #print()
126
- #print(thing.metadata)
127
- #sources = [doc.metadata['source'] for doc in chunk['context']]
128
-
129
- #response = rag_chain_with_source.invoke(prompt)
130
- #answer = response["answer"]
131
- #sources_txt = "\n\nSources:\n" + "\n".join(sources)
132
- #yield sources_txt
133
-
134
- #question = "How can I do hybrid search with a pinecone database?"
135
- #answer = generate_response(question)
136
- #print(answer)
137
 
138
  # ==================== THE REST OF THE STREAMLIT APP ====================
139
 
 
42
  index = pc.Index(index_name)
43
 
44
  # ========== PART 3 ==========
45
+
46
+ text_field = "child_content"
47
+
48
  splade_encoder = SpladeEncoder()
49
  retriever = PineconeHybridSearchRetriever(
50
+ embeddings=embed, sparse_encoder=splade_encoder, index=index, text_field
51
  )
52
 
53
 
 
98
 
99
  rag_chain = (
100
  RunnablePassthrough()
101
+ | SourceDedup()
102
+ | PassParentContent()
103
  | prompt
104
  | model
105
  | StrOutputParser()
 
123
  elif list(chunk.keys())[0] == 'context':
124
  pass
125
  # Sources DO NOT work the same with this code... removing for now.
126
+ sources = chunk['context']
127
+ for thing in chunk['context']:
128
+ print()
129
+ print(thing.metadata)
130
+ sources = [doc.metadata['source'] for doc in chunk['context']]
131
+
132
+ response = rag_chain_with_source.invoke(prompt)
133
+ answer = response["answer"]
134
+ sources_txt = "\n\nSources:\n" + "\n".join(sources)
135
+ yield sources_txt
136
+
137
+ question = "How can I do hybrid search with a pinecone database?"
138
+ answer = generate_response(question)
139
+ print(answer)
140
 
141
  # ==================== THE REST OF THE STREAMLIT APP ====================
142