Skip to content

Commit

Permalink
fixed but when using Vectara query engine in non-summary mode (#11668)
Browse files Browse the repository at this point in the history
* fixed but when using Vecrtara query engine in non-summary node - it needs to have output synthesizers after refactor

* updated vectara autoRetriever example notebook

* bugfix

* bugfix in handling error
updated documentId has to be 64 characters (instead of longer)

* fixes from review

* fix per review
  • Loading branch information
ofermend authored Mar 7, 2024
1 parent d0cc330 commit a3491cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
13 changes: 11 additions & 2 deletions docs/examples/retrievers/vectara_auto_retriever.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index"
"!pip install llama-index llama-index-indices-managed-vectara llama-index-llms-openai"
]
},
{
Expand Down Expand Up @@ -222,6 +222,7 @@
"source": [
"import getpass\n",
"import openai\n",
"import os\n",
"\n",
"if not os.environ.get(\"OPENAI_API_KEY\", None):\n",
" os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")\n",
Expand Down Expand Up @@ -290,11 +291,17 @@
"metadata": {},
"outputs": [],
"source": [
"llm = OpenAI(model=\"gpt-4-1106-preview\", temperature=0)\n",
"from llama_index.indices.managed.vectara import VectaraAutoRetriever\n",
"from llama_index.core.indices.service_context import ServiceContext\n",
"from llama_index.llms.openai import OpenAI\n",
"\n",
"llm = OpenAI(model=\"gpt-3.5-turbo\", temperature=0)\n",
"\n",
"retriever = VectaraAutoRetriever(\n",
" index,\n",
" vector_store_info=vector_store_info,\n",
" llm=llm,\n",
" verbose=False,\n",
")"
]
},
Expand Down Expand Up @@ -395,6 +402,7 @@
"retriever = VectaraAutoRetriever(\n",
" index,\n",
" vector_store_info=vector_store_info,\n",
" llm=llm,\n",
" filter=\"doc.rating > 8\",\n",
")\n",
"retriever.retrieve(\"movie about toys\")"
Expand Down Expand Up @@ -438,6 +446,7 @@
"retriever = VectaraAutoRetriever(\n",
" index,\n",
" vector_store_info=vector_store_info,\n",
" llm=llm,\n",
" filter=\"doc.rating > 8\",\n",
" vectara_query_mode=\"mmr\",\n",
" mmr_k=50,\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
from llama_index.core.settings import Settings
from llama_index.core.storage.storage_context import StorageContext

from llama_index.core.response_synthesizers import ResponseMode
from llama_index.core import get_response_synthesizer

_logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -193,13 +196,12 @@ def _index_doc(self, doc: dict) -> str:
)

status_code = response.status_code

result = response.json()

status_str = result["status"]["code"] if "status" in result else None
if status_code == 409 or status_str and (status_str == "ALREADY_EXISTS"):
if status_code == 409 and status_str and (status_str == "ALREADY_EXISTS"):
return "E_ALREADY_EXISTS"
elif status_code == 200 or status_str and (status_str == "INVALID_ARGUMENT"):
elif status_code == 200 and status_str and (status_str == "INVALID_ARGUMENT"):
return "E_INVALID_ARGUMENT"
elif status_str and (status_str == "FORBIDDEN"):
return "E_NO_PERMISSIONS"
Expand All @@ -215,7 +217,7 @@ def _insert(
"""Insert a set of documents (each a node)."""

def gen_hash(s: str) -> str:
hash_object = blake2b()
hash_object = blake2b(digest_size=32)
hash_object.update(s.encode("utf-8"))
return hash_object.hexdigest()

Expand Down Expand Up @@ -360,8 +362,14 @@ def as_query_engine(
)

retriever = self.as_retriever(**kwargs)
response_synthesizer = get_response_synthesizer(
response_mode=ResponseMode.COMPACT,
llm=llm,
)
return RetrieverQueryEngine.from_args(
retriever=retriever, llm=llm, **kwargs
retriever=retriever,
response_synthesizer=response_synthesizer,
**kwargs,
)

@classmethod
Expand Down

0 comments on commit a3491cf

Please sign in to comment.