from langchain.retrievers.self_query.base import SelfQueryRetriever
from langchain.chains.query_constructor.base import AttributeInfo
from datetime import datetime

current_time_iso = datetime.utcnow().isoformat() + "Z"


# example metadat
"""
{
  "type": "file_load_gcs",
  "attrs": "namespace:edmonbrain",
  "source": "gs://devoteam-mark-langchain-loader/edmonbrain/MarkWork/Running LLMs on Google Cloud Platform via Cloud Run, VertexAI and PubSub - LLMOps on GCP.md",
  "bucketId": "devoteam-mark-langchain-loader",
  "category": "NarrativeText",
  "filename": "Running LLMs on Google Cloud Platform via Cloud Run, VertexAI and PubSub - LLMOps on GCP.md",
  "filetype": "text/markdown",
  "objectId": "edmonbrain/MarkWork/Running LLMs on Google Cloud Platform via Cloud Run, VertexAI and PubSub - LLMOps on GCP.md",
  "eventTime": "2023-07-12T19:36:07.325740Z",
  "eventType": "OBJECT_FINALIZE",
  "bucket_name": "devoteam-mark-langchain-loader",
  "page_number": 1,
  "payloadFormat": "JSON_API_V1",
  "objectGeneration": "1689190567243818",
  "notificationConfig": "projects/_/buckets/devoteam-mark-langchain-loader/notificationConfigs/1"
}
"""

metadata_field_info = [
    AttributeInfo(
        name="source",
        description="The document source url or path to where the document is located",
        type="string",
    ),
    AttributeInfo(
        name="eventTime",
        description=f"When this content was put into the memory.  The current datetime is {current_time_iso}",
        type="ISO 8601 formatted date and time string",
    ),
    AttributeInfo(
        name="type",
        description="How this content was added to the memory",
        type="string",
    ),
]
document_content_description = "Documents stored in the bot long term memory"

def get_self_query_retriever(llm, vectorstore):

    return SelfQueryRetriever.from_llm(
        llm, vectorstore, document_content_description, metadata_field_info, verbose=True
    )

langchain.retrievers.self_query.base.SelfQueryRetriever.from_llm langchain.chains.query_constructor.base.AttributeInfo
[((1179, 1311), 'langchain.chains.query_constructor.base.AttributeInfo', 'AttributeInfo', ([], {'name': '"""source"""', 'description': '"""The document source url or path to where the document is located"""', 'type': '"""string"""'}), "(name='source', description=\n    'The document source url or path to where the document is located',\n    type='string')\n", (1192, 1311), False, 'from langchain.chains.query_constructor.base import AttributeInfo\n'), ((1339, 1531), 'langchain.chains.query_constructor.base.AttributeInfo', 'AttributeInfo', ([], {'name': '"""eventTime"""', 'description': 'f"""When this content was put into the memory.  The current datetime is {current_time_iso}"""', 'type': '"""ISO 8601 formatted date and time string"""'}), "(name='eventTime', description=\n    f'When this content was put into the memory.  The current datetime is {current_time_iso}'\n    , type='ISO 8601 formatted date and time string')\n", (1352, 1531), False, 'from langchain.chains.query_constructor.base import AttributeInfo\n'), ((1558, 1660), 'langchain.chains.query_constructor.base.AttributeInfo', 'AttributeInfo', ([], {'name': '"""type"""', 'description': '"""How this content was added to the memory"""', 'type': '"""string"""'}), "(name='type', description=\n    'How this content was added to the memory', type='string')\n", (1571, 1660), False, 'from langchain.chains.query_constructor.base import AttributeInfo\n'), ((1829, 1943), 'langchain.retrievers.self_query.base.SelfQueryRetriever.from_llm', 'SelfQueryRetriever.from_llm', (['llm', 'vectorstore', 'document_content_description', 'metadata_field_info'], {'verbose': '(True)'}), '(llm, vectorstore, document_content_description,\n    metadata_field_info, verbose=True)\n', (1856, 1943), False, 'from langchain.retrievers.self_query.base import SelfQueryRetriever\n'), ((184, 201), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (199, 201), False, 'from datetime import datetime\n')]