Comments (1)
To ensure that the chatbot uses the retriever only when the question is related to ingested documents, you can implement a check within the _generate_context
and _agenerate_context
methods of the ContextChatEngine
class. This check can determine if the query is related to the ingested documents before proceeding with the retrieval process.
Here is an example of how you might modify the _generate_context
and _agenerate_context
methods to include such a check:
class ContextChatEngine(BaseChatEngine):
# ... other methods ...
def _generate_context(self, message: str) -> Tuple[str, List[NodeWithScore]]:
"""Generate context information from a message."""
if not self._is_related_to_ingested_documents(message):
return "The question is not related to the ingested documents.", []
nodes = self._retriever.retrieve(message)
for postprocessor in self._node_postprocessors:
nodes = postprocessor.postprocess_nodes(
nodes, query_bundle=QueryBundle(message)
)
context_str = "\n\n".join(
[n.node.get_content(metadata_mode=MetadataMode.LLM).strip() for n in nodes]
)
return self._context_template.format(context_str=context_str), nodes
async def _agenerate_context(self, message: str) -> Tuple[str, List[NodeWithScore]]:
"""Generate context information from a message."""
if not self._is_related_to_ingested_documents(message):
return "The question is not related to the ingested documents.", []
nodes = await self._retriever.aretrieve(message)
for postprocessor in self._node_postprocessors:
nodes = postprocessor.postprocess_nodes(
nodes, query_bundle=QueryBundle(message)
)
context_str = "\n\n".join(
[n.node.get_content(metadata_mode=MetadataMode.LLM).strip() for n in nodes]
)
return self._context_template.format(context_str=context_str), nodes
def _is_related_to_ingested_documents(self, query_str: str) -> bool:
# Implement your logic to determine if the query is related to ingested documents
# For example, you could check for specific keywords or use a more complex NLP model
return True # Placeholder implementation
In this example, the _is_related_to_ingested_documents
method should contain the logic to determine if the query is related to the ingested documents. This could be a simple keyword check or a more sophisticated natural language processing (NLP) model. If the query is not related, the method returns a message indicating that the question is not related to the ingested documents [1][2][3].
To continue talking to Dosu, mention @dosu.
from llama_index.
Related Issues (20)
- [Question]: How big of a VectorStore is too big ? HOT 1
- [Bug]: llama-index-llms-langchain is not working with latest lanchain HOT 2
- [Bug]: Function Tool not being hit when it's a SubQuestionQueryEngine in OpenAIAgent HOT 3
- [Feature Request]: Improve ElasticSearch metadata filtering handling
- [Question]: cannot download sharepoint file HOT 2
- [Question]: Connecting llamaindex to aoss opensearch on aws HOT 7
- [Bug]: 'await' used outside function HOT 4
- [Question]: TokenCountingHandler is not working for Multimodal HOT 3
- [Question]: how to use faiss.IndexIVFPQ? HOT 1
- [Question]: Why is JSONalyze using `columns_dict` of the `sqlite_utils`? HOT 2
- [Bug]: HOT 2
- Chromadb embeddings not working with densex HOT 1
- [Bug]: pipeline arun does not parallelize query pipeline HOT 3
- Json +pdf engine HOT 1
- [Question]: SentenceNodeParser ignores max_length of embed model HOT 4
- [Bug]: Unable to run UnstructuredElementNodeParser with OpenAILike LLM HOT 2
- [Feature Request]: Async support for Qdrant Vector store HOT 2
- [Question]: when break complex problem into sub-problems raise “JSONDecodeError" HOT 5
- [Question]: is default in VectorIndexRetriever semantic search HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llama_index.