Knowledge -- any working examples?

Hi, does anyone have a working example for PDFknowledgesource please?
Huge thanks!

I am assuming this package is correct?

from crewai.knowledge.source.pdf_knowledge_source import PDFKnowledgeSource

I’ve tried the following approached so far, neither I can get working.

knowledge_source = PDFKnowledgeSource(
file_path=“filename.pdf”,
chunk_size=2000, # Characters per chunk
chunk_overlap=200 # Overlap between chunks
)

knowledge_source = PDFKnowledgeSource(
“filename.pdf”
)

What error do you get?

Seems like I am not providing the right information?

Field required [type=missing, input_value={}, input_type=dict]

Running the Crew
warning: VIRTUAL_ENV=/home/user/crewai/.venv does not match the project environment path .venv and will be ignored
Traceback (most recent call last):
File “/home/user/crewai/demo/.venv/bin/run_crew”, line 5, in
from demo.main import run
File “/home/user/crewai/demo/src/demo/main.py”, line 5, in
from demo.crew import Demo
File “/home/user/crewai/demo/src/demo/crew.py”, line 17, in
knowledge_source = PDFKnowledgeSource()
^^^^^^^^^^^^^^^^^^^^
File “/home/user/crewai/demo/.venv/lib/python3.11/site-packages/pydantic/main.py”, line 214, in init
validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for PDFKnowledgeSource
file_path
Field required [type=missing, input_value={}, input_type=dict]
For further information visit Redirecting...
An error occurred while running the crew: Command ‘[‘uv’, ‘run’, ‘run_crew’]’ returned non-zero exit status 1.

@Daniel_Ryan What’s your CrewAI SDK version? What LLM are you using?

crewai version: 0.85.0
Using OpenAI, API Key

Struggled with other models too, so reverted to simplest implementation to try to determine the root cause/issue.

Hi, any update?
Does anyone have a working example on how to use Knowledge with PDF files?

PDFKnowledgeSource

Thanks
Danny

Hey @Daniel_Ryan

Here is the code snippet of my crew:

   @crew
def crew(self) -> Crew:
	pdf_source = PDFKnowledgeSource(file_path="Knowledge.pdf")
	return Crew(
		agents=self.agents,
		tasks=self.tasks,
		process=Process.sequential,
		verbose=True,
		knowledge_sources=[pdf_source]
	)

Store the pdf file in project home directory under the folder named knowledge. Below is my file structure:

crewai version: 0.76.9

Good luck!!

1 Like

Thanks, I was able to get past the Knowledge configuration. I had to provide the full pdf filename path.

I get a new error now… So off to figure this one out…

ValueError: Something went wrong. Kickoff should return only one task output.

I forgot to include my Task decorator :doh:
This thread can be marked as closed/resolved, thank you!

1 Like