Spaces:
Running
Running
File size: 1,608 Bytes
a71ea0a 66c4741 a71ea0a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | """
Example script showing how to use the document ingestion system programmatically.
"""
from ingestion import DocumentIngestion
def main():
# Initialize the ingestion system
ingestion = DocumentIngestion(embedding_model="all-MiniLM-L6-v2")
# Example 1: Process PDFs
pdf_paths = [
# Add your PDF file paths here
# "path/to/document1.pdf",
# "path/to/document2.pdf",
]
# Example 2: Process URLs
urls = [
# Add URLs here
# "https://en.wikipedia.org/wiki/Artificial_intelligence",
# "https://huggingface.co/docs/transformers",
]
# Process documents
if pdf_paths or urls:
print("Processing documents...")
documents = ingestion.process_documents(pdf_paths=pdf_paths, urls=urls)
print(f"Processed {len(documents)} document chunks")
# Build vector store
ingestion.build_vector_store()
# Save vector store
ingestion.save("data/vector_store")
# Example search
query = "What is artificial intelligence?"
results = ingestion.search(query, k=3)
print(f"\nSearch results for: '{query}'")
print("-" * 50)
for i, result in enumerate(results, 1):
print(f"\nResult {i}:")
print(f"Source: {result['metadata']['source']}")
print(f"Score: {result['score']:.4f}")
print(f"Text: {result['text'][:200]}...")
else:
print("Please add PDF paths or URLs to the script to test ingestion.")
if __name__ == "__main__":
main()
|