Retrieve the content_id after a knowledge.add_content

I am very impressed with this amazing framework, thank you! I apologize in advance for any awkward phrasing, as I am not a native English speaker :sweat_smile: .

I am currently working on building knowledge bases. I’ve encountered the following problem: How do I retrieve the content_id for content added using the knowledge.add_content() method?

he system allows for individual user-owned knowledge bases. The relationship is one-to-many from a knowledge base to its versions, and one-to-many from each version to its constituent files

I noticed that the method has no return value, so I cannot do: content = knowledge.add_content

I considered using metadata and then fetching the ID via SQL after insertion, but I don’t think that is the best approach.

Below is a snippet of the code. Thank you in advance for your understanding.

@router**.**post(“/content”)

def add_content():

pdf_path = Path(\__file_\_)**.**resolve()**.**parent / "doc_api.pdf"



embedder = OpenAIEmbedder(

    id="text-embedding-3-small", api_key="my_api_key"

)



vector = PgVector(

    table_name="doc_api_v1",

    schema="public",

    db_engine=postgres_engine,

    embedder=embedder,

)



db = PostgresDb(db_engine=postgres_engine, db_schema="public")



knowledge = Knowledge(

    vector_db=vector,

    contents_db=db,

)



content_id = str(uuid4())



knowledge**.**add_content(

    name="API Documentation",

    description="Description API methods",

    path=pdf_path,

    reader=PDFReader(

        chunking_strategy=SemanticChunking(

            chunk_size=1000, similarity_threshold=0.5

        )

    ),

    metadata={"content_id": content_id},

)

return {"ok": True}

Hey @weslen.barbosa, thank you for reaching out and supporting Agno!
I saw that your query was addressed in GitHub. Let me know if you have any more further questions, we’re here to help.