Skip to main content

No project description provided

Project description

SynapseAI: Semantic Search Without LLMs

This package provides an AI-powered document semantic search system that doesn't rely on large language models (LLMs). It allows you to process documents, web content, and scanned images, and then perform efficient semantic searches using cosine similarity.

Installation

Install the package using pip:

pip install SynapseAI

Load a Document

To load a document (PDF, DOCX, TXT, XLS, XLSX):

from SynapseAI.data_loader import DataLoader

# Load a document
data_loader = DataLoader("path/to/document.pdf")
documents = data_loader.load_document()

Chunk the Document

To chunk the document into smaller pieces:

# Chunk the document into smaller pieces
chunks = data_loader.chunk_document(documents, chunk_size=1024, chunk_overlap=80)

Process the Chunks

This step creates embeddings for the document chunks and builds a FAISS index for efficient similarity search:

from SynapseAI.utils import process_chunks

process_chunks(chunks)

Web Crawling

Crawl a Website

To crawl a website and fetch its content:

from SynapseAI.web_crawler import WebCrawler

# Crawl a website
url = WebCrawler("https://www.example.com")
content = crawler.fetch_content()

Process the Crawled Content

To process the content fetched from the website:

from SynapseAI.utils import process_chunks
from langchain.schema import Document as LangChainDocument

document = LangChainDocument(page_content=content, metadata={"source": url})
chunks = DataLoader("").chunk_document([document], chunk_size=1024, chunk_overlap=80)
process_chunks(chunks)

Semantic Search

Perform a Semantic Search

To perform a semantic search using the FAISS index and retrieve the top matching document chunks:

from SynapseAI.utils import cosine_similarity, load_embeddings
import numpy as np

# Load the embeddings
embeddings = load_embeddings()

# Define a query
query = "What is the main topic of the document?"
query_embedding = embeddings.embed_query(query)

# Reconstruct the document embeddings
from SynapseAI.utils import FAISS
# Pass the chunks you made 
vectorstore = FAISS.from_documents(documents=chunks, embedding=embeddings)
document_embeddings = vectorstore.index.reconstruct_n(0, vectorstore.index.ntotal)

# Calculate similarities and get the top results
similarities = [cosine_similarity(query_embedding, doc_embedding) for doc_embedding in document_embeddings]
top_k_indices = np.argsort(similarities)[-5:][::-1]

for i, idx in enumerate(top_k_indices):
    doc = vectorstore.docstore.search(vectorstore.index_to_docstore_id[idx])
    print(f"Match {i+1} - Similarity: {similarities[idx]:.4f}")
    print(doc.page_content)

This example shows how to load the embeddings, perform a semantic search using the FAISS index, and retrieve the top matching document chunks.

Customization

You can customize the behavior of the document processing by adjusting the chunk_size and chunk_overlap parameters when calling the chunk_document() method. Larger chunk sizes provide more context, while smaller chunks can improve search precision.

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synapseai-0.3.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SynapseAI-0.3.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file synapseai-0.3.3.tar.gz.

File metadata

  • Download URL: synapseai-0.3.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for synapseai-0.3.3.tar.gz
Algorithm Hash digest
SHA256 8073e1ecdb5030dcecff822f812825908d806595c52b7f1f0d030325db7e0fb1
MD5 3cb9ca9a1e394a6a5c01e712c1de73ab
BLAKE2b-256 d489b737dca30b03c6ae0c91e70182da41585a4e70ca26505eadf1ddcfd5a32c

See more details on using hashes here.

File details

Details for the file SynapseAI-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: SynapseAI-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for SynapseAI-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ba7e97b36417d8697d80163f2982e9dd25fdd8afa48e484a8be5b02b4ef6730c
MD5 93a774d991a34ad700c85126532cb77a
BLAKE2b-256 f59ce1682efd1d200d50a26dc8188ee70d9682347c3afd102292d5cf84b02ec0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page