Tonic commited on
Commit
363cb1e
1 Parent(s): a6d437d

add jina embeddings and reranker

Browse files
Files changed (1) hide show
  1. yijinaembed.py +4 -4
yijinaembed.py CHANGED
@@ -20,8 +20,8 @@ import spaces
20
  from langchain.retrievers.contextual_compression import ContextualCompressionRetriever
21
  from langchain_community.document_compressors.jina_rerank import JinaRerank
22
  from langchain import hub
23
- from langchain.chains import create_retrieval_chain
24
- from langchain.chains.retrieval import create_stuff_documents_chain
25
 
26
  load_dotenv()
27
 
@@ -140,7 +140,7 @@ def add_documents_to_chroma(documents: list, embedding_function: JinaEmbeddingFu
140
  @spaces.GPU
141
  def rerank_documents(query: str, documents: List[str]) -> List[str]:
142
  compressor = JinaRerank()
143
- retriever = chroma_db.as_retriever(search_kwargs={"k": 20})
144
  compression_retriever = ContextualCompressionRetriever(
145
  base_compressor=compressor, base_retriever=retriever
146
  )
@@ -153,7 +153,7 @@ def query_chroma(query_text: str, embedding_function: JinaEmbeddingFunction):
153
  query_embeddings, query_metadata = embedding_function.compute_embeddings(query_text)
154
  result_docs = chroma_collection.query(
155
  query_embeddings=[query_embeddings],
156
- n_results=3
157
  )
158
  return result_docs
159
 
 
20
  from langchain.retrievers.contextual_compression import ContextualCompressionRetriever
21
  from langchain_community.document_compressors.jina_rerank import JinaRerank
22
  from langchain import hub
23
+ from langchain.chains.retrieval import create_retrieval_chain
24
+ from langchain.chains.combine_documents.stuff import create_stuff_documents_chain
25
 
26
  load_dotenv()
27
 
 
140
  @spaces.GPU
141
  def rerank_documents(query: str, documents: List[str]) -> List[str]:
142
  compressor = JinaRerank()
143
+ retriever = chroma_db.as_retriever(search_kwargs={"k": 15})
144
  compression_retriever = ContextualCompressionRetriever(
145
  base_compressor=compressor, base_retriever=retriever
146
  )
 
153
  query_embeddings, query_metadata = embedding_function.compute_embeddings(query_text)
154
  result_docs = chroma_collection.query(
155
  query_embeddings=[query_embeddings],
156
+ n_results=5
157
  )
158
  return result_docs
159