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)
- How to use 'Azure Cosmos DB for MongoDB account (RU)' instance as DocStore to store document nodes HOT 4
- First Retrieval on Chroma Vector Store is Significantly Slow[Bug]: HOT 3
- [Bug]:Perplexity LLM integration list outdated HOT 1
- [Bug]: Workflow steps appear to be blocking? HOT 2
- PandasAIReader.__init__() got an unexpected keyword argument 'llm'[Bug]: HOT 2
- DuckDB vector database Tutorial HOT 1
- [Feature Request]: Store-agnostic interface for retrieving document embeddings from vector index HOT 5
- [Question]: AzureChatStore: Ensuring Asynchronous Requests and Understanding _atable_service_client Usage HOT 2
- [Feature Request]: FaissVectorStore with metadata support
- [Question]: Value Prop of LlamaIndex Workflows over LangGraph? HOT 1
- [Bug]: WARNING:llama_index.embeddings.openai.utils:Retrying llama_index.embeddings.openai.base.get_embeddings in 0.7360705661705746 seconds as it raised APIConnectionError: Connection error.. HOT 1
- [Question]: How to handle complex PDFs HOT 2
- [Feature Request]: Support for locally hosted LLM API HOT 1
- [Bug]: MistralAI chat_completion API broken HOT 6
- [Bug]: EmptyNetworkError HOT 2
- [Documentation]: Fix Import Statement in 'Using as a Retriever' Section HOT 1
- [Question]: How to use Azure Table Storage for indexing large files HOT 10
- [Feature Request]: Leveraging MapReduce and LLMs for Big Data Systems - A Potential Benefit for Your Project
- [Bug]: Agent responds with accurate SQL query but then throws error HOT 3
- [Question]: llama_index.llms.openai.base.OpenAI._achat raised APIConnectionError: Connection error.. HOT 7
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.