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
.
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}