Skip to main content
Glama

MCP RAG Server

vector_store.cpython-313.pyc6.06 kB
� L��gW��L�SSKrSSKrSSKrSSKrSSKJrJrJr "SS5r g)�N)�List�Dict�Anyc ��\rSrSrSS\4SjjrS\\\\ 44Sjr SS\ RS\S\\\\ 44S jjr S \4S jrS \4S jrS rg)�FAISSVectorStore�� dimensionc�T�Xl[R"U5Ul/Ulg)zT Initialize a FAISS vector store. Args: dimension: Dimension of the embeddings N)r �faiss� IndexFlatL2�index� documents)�selfr s �6/Users/kz/vcs/sui-ai/mcp_server/models/vector_store.py�__init__�FAISSVectorStore.__init__s"��#���&�&�y�1�� ����rc��U(dg/n/nUH�nSU;ak[US[R5(aIURUS5 UR 5nUR SS5 URU5 Mt[ SURSS535 M� U(d [ S5 g[R"U5RS5nURRU5 [UR5nURRU5 [ S[U5S [UR535 g) zt Index a list of documents. Args: documents: List of document dictionaries with 'embedding' and other metadata N� embeddingz/Warning: Document missing embedding, skipping: �id�unknownz&No valid embeddings found in documents�float32zAdded z documents to index. Total: )� isinstance�np�ndarray�append�copy�pop�print�get�array�astyper �add�lenr�extend)rr� embeddings� updated_docs�doc�doc_copy�embeddings_array� start_idxs r�index_documents� FAISSVectorStore.index_documentss��� �� �� ��C��c�!�j��[�1A�2�:�:�&N�&N��!�!�#�k�"2�3��8�8�:��� � �[�$�/��#�#�H�-��G����PT�V_�H`�Ga�b�c��� �:� ;� ��8�8�J�/�6�6�y�A�� � � ���'�(�����'� � �����l�+� ��s�:��'�'C�C����DW�CX�Y�Zr�query_embedding�top_k�returnc�N�[UR5S:Xa/$[UR5S:Xa[R"USS9nUR S5n[ U[UR55nURRX5up4/n[[USUS55HmunupxU[UR5:dM#US:�dM+URUR5n [SSU-- 5U S'URU 5 Mo U$)z� Search for similar documents using a query embedding. Args: query_embedding: The embedding vector of the query top_k: Number of results to return Returns: List of document dictionaries with similarity scores r�)�axisrg�?�score)r$r�shaper� expand_dimsr"�minr �search� enumerate�zipr�floatr) rr.r/� distances�indices�results�i�dist�idxr(s rr8�FAISSVectorStore.search9s�� �t�~�~� �!� #��I� ��$�$� %�� *� �n�n�_�1�E�O�*�0�0��;���E�3�t�~�~�.�/��"�Z�Z�.�.��F�� ���'��I�a�L�'�!�*�(E�F�N�A�{���S����(�(�S�A�X��n�n�S�)�.�.�0��$�S�C�$�J�%7�8��G� ����s�#� G� �r�filepathc��[R"[RRU5SS9 [R "UR U5 [US3S5n[R"URU5 SSS5 [S[UR5SU35 g!,(df  N3=f)zS Save the index and documents to disk. Args: filepath: Path to save the index T)�exist_ok� .documents�wbNzSaved index with z documents to ) �os�makedirs�path�dirnamer � write_indexr �open�pickle�dumprrr$)rrC�fs r�save�FAISSVectorStore.save^s��� � � �B�G�G�O�O�H�-��=� ���$�*�*�h�/��X�J�j�)�4� 0�A� �K�K����� *�1� �!�#�d�n�n�"5�!6�n�X�J�O�P�1� 0�s �#"B2�2 Cc��[RRU5(a[R"U5UlO[ SU35eUS3n[RRU5(a0[US5n[R"U5Ul SSS5 [S[UR5SU35 g!,(df  N3=f)zZ Load the index and documents from disk. Args: filepath: Path to load the index from zIndex file not found: rF�rbNzLoaded index with z documents from ) rHrJ�existsr � read_indexr �FileNotFoundErrorrMrN�loadrrr$)rrC�doc_pathrPs rrX�FAISSVectorStore.loadps��� �7�7�>�>�(� #� #��)�)�(�3�D�J�#�&<�X�J�$G�H� H��Z�z�*�� �7�7�>�>�(� #� #��h��%��!'���Q����&� �"�3�t�~�~�#6�"7�7G��z�R�S�&�%�s �C � C)r rr N)i)�)�__name__� __module__� __qualname__�__firstlineno__�intrrr�strrr,rrr8rQrX�__static_attributes__�rrrrss�� �#� �$[��d�3��8�n�)=�$[�L#�b�j�j�#��#�T�$�s�TW�x�.�EY�#�JQ�S�Q�$T�S�Trr) rH�numpyrr rN�typingrrrrrcrr�<module>rfs%�� �� � �"�"�|T�|Tr

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ProbonoBonobo/sui-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server