Replies: 1 comment
-
Hey @shanumas! 👋 I'm here to help you with any questions or issues you have. I'm a bot that can assist with bug fixes, answering questions, and getting you ready to contribute. Let me know how I can assist you! You should write the custom query for prefiltering in the # Perform a similarity search with a filter
query = "What did the president say about Ketanji Brown Jackson"
filter = {"field_name": {"$gte": value}} # Replace with your actual filter criteria
docs = vectorstore.similarity_search(query, filter=filter)
print(docs[0].page_content) This code snippet shows how to add a filter to the To integrate custom metadata extraction and comparison logic into the Here is an example of how you can modify the from qdrant_client.http import models as rest
class QdrantTranslator(Visitor):
def __init__(self, metadata_key: str):
self.metadata_key = metadata_key
def visit_comparison(self, comparison: Comparison) -> rest.FieldCondition:
self._validate_func(comparison.comparator)
attribute = self.metadata_key + "." + comparison.attribute
# Custom metadata extraction logic
if isinstance(comparison.value, dict) and 'custom_metadata' in comparison.value:
custom_metadata = comparison.value['custom_metadata']
# Apply custom logic to extract metadata
comparison.value = self.extract_custom_metadata(custom_metadata)
if comparison.comparator == Comparator.EQ:
return rest.FieldCondition(
key=attribute, match=rest.MatchValue(value=comparison.value)
)
if comparison.comparator == Comparator.LIKE:
return rest.FieldCondition(
key=attribute, match=rest.MatchText(text=comparison.value)
)
kwargs = {comparison.comparator.value: comparison.value}
return rest.FieldCondition(key=attribute, range=rest.Range(**kwargs))
def extract_custom_metadata(self, custom_metadata: dict) -> Any:
# Implement your custom metadata extraction logic here
# For example, you can extract specific fields or transform the metadata
return custom_metadata.get('specific_field', 'default_value') Additionally, you can refer to the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
My self query extractor is working fine. But I just want llm to extract the metadata. I want to write my custom query. I want to decide whether it should the metadata coparison should be "gte" or "lte" . How can I do it here ?
System Info
Beta Was this translation helpful? Give feedback.
All reactions