Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3239094
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:55:46+00:00 2026-05-17T17:55:46+00:00

I have a full inverted index in form of nested python dictionary. Its structure

  • 0

I have a full inverted index in form of nested python dictionary. Its structure is :

{word : { doc_name : [location_list] } }

For example let the dictionary be called index, then for a word ” spam “, entry would look like :

{ spam : { doc1.txt : [102,300,399], doc5.txt : [200,587] } }

I used this structure as python dict are pretty optimised and it makes programming easier.

for any word ‘spam’, the documents containig it can be given by :

index['spam'].keys()

and posting list for a document doc1 by:

index['spam']['doc1']

At present I am using cPickle to store and load this dictionary. But the pickled file is around 380 MB and takes a long time to load – 112 seconds(approx. I timed it using time.time()) and memory usage goes to 1.2 GB (Gnome system monitor). Once it loads, its fine. I have 4GB RAM.

len(index.keys()) gives 229758

Code

import cPickle as pickle

f = open('full_index','rb')
print 'Loading index... please wait...'
index = pickle.load(f)  # This takes ages
print 'Index loaded. You may now proceed to search'

How can I make it load faster? I only need to load it once, when the application starts. After that, the access time is important to respond to queries.

Should I switch to a database like SQLite and create an index on its keys? If yes, how do I store the values to have an equivalent schema, which makes retrieval easy. Is there anything else that I should look into ?

Addendum

Using Tim’s answer pickle.dump(index, file, -1) the pickled file is considerably smaller – around 237 MB (took 300 seconds to dump)… and takes half the time to load now (61 seconds … as opposed to 112 s earlier …. time.time())

But should I migrate to a database for scalability ?

As for now I am marking Tim’s answer as accepted.

PS :I don’t want to use Lucene or Xapian …
This question refers Storing an inverted index . I had to ask a new question because I wasn’t able to delete the previous one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:55:47+00:00Added an answer on May 17, 2026 at 5:55 pm

    Try the protocol argument when using cPickle.dump/cPickle.dumps. From cPickle.Pickler.__doc__:

    Pickler(file, protocol=0) — Create a pickler.

    This takes a file-like object for writing a pickle data stream.
    The optional proto argument tells the pickler to use the given
    protocol; supported protocols are 0, 1, 2. The default
    protocol is 0, to be backwards compatible. (Protocol 0 is the
    only protocol that can be written to a file opened in text
    mode and read back successfully. When using a protocol higher
    than 0, make sure the file is opened in binary mode, both when
    pickling and unpickling.)

    Protocol 1 is more efficient than protocol 0; protocol 2 is
    more efficient than protocol 1.

    Specifying a negative protocol version selects the highest
    protocol version supported. The higher the protocol used, the
    more recent the version of Python needed to read the pickle
    produced.

    The file parameter must have a write() method that accepts a single
    string argument. It can thus be an open file object, a StringIO
    object, or any other custom object that meets this interface.

    Converting JSON or YAML will probably take longer than pickling most of the time – pickle stores native Python types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I'm doing is I have a full-screen form, with no title bar, and
If I have Full Control permission on a list, is there a way for
Does Microsoft Access have Full Text Search? I know that MySQL and SQL Server
If I start a process via Java's ProcessBuilder class, I have full access to
I have a full path which I would like to remove certain levels of
I have a full MS SQL Backup file that I would like to extract
Suppose you have a full path to an accessible file or folder on the
We should have a full release of asp.net MVC well before .NET 4.0 and
I'd like my application to have a full-screen mode. What is the easiest way
I have a database full of customer data. It's so big that it's really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.