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
crawler = WebCrawler("https://www.example.com")
content = crawler.fetch_content()
Process the Crawled Content
To process the content fetched from the website:
from langchain.schema import Document as LangChainDocument
document = LangChainDocument(page_content=content, metadata={"source": "https://www.example.com"})
chunks = data_loader.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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file synapseai-0.3.2.tar.gz.
File metadata
- Download URL: synapseai-0.3.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
998a9d4f9fc21df2443e2456669f60a059756e4e4ddff2471249b17325d601a0
|
|
| MD5 |
e3529ca8a6f4263174dac8718c2445d0
|
|
| BLAKE2b-256 |
9e9fede1f030c39abf068a6936a23ab198c3ba5093a3e7c4866f55096cfad473
|
File details
Details for the file SynapseAI-0.3.2-py3-none-any.whl.
File metadata
- Download URL: SynapseAI-0.3.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb753f747ecd327ee738cbfb1e17d4b00dcb854498126fdd6cc9f5508e96e03a
|
|
| MD5 |
84183e9aba47a3b8f1a9133abbb526b1
|
|
| BLAKE2b-256 |
ba0f3d689a0771c39546f284c251f16164f6ae0fe1af12b6e0723e55c0dce316
|